ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: radu81 on December 11, 2016, 08:29:54 pm

Title: Bug with links inserted with HTTP in uppercase
Post by: radu81 on December 11, 2016, 08:29:54 pm
test
Code: [Select]
https://www.google.it
https://www.google.it


Code: [Select]
Https://www.google.it
Https://www.google.it


Code: [Select]
HTTP://www.google.itt
HTTP://www.google.it


it happens to elkarte 1.0.x but also here on elkarte 1.1
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: Burke Knight on December 12, 2016, 07:55:38 am
Looks like it's not seeing the caps as the http for some odd reason.
Wonder if you know what also had this.

Okay, after testing on an old, old, site, yes, this is a SMF problem, as well.  :D
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: radu81 on December 12, 2016, 08:11:54 am
I think this could be solved using the "Censored word" function included into elkarte/smf, I did not test it but should work.
Anyway will be better if solved into the core ;)

Good to know this is also an SMF bug, did you alredy reported to SMF @Burke Knight‍ ?

edit: reported also to SMF http://www.simplemachines.org/community/index.php?topic=550527
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: Spuds on December 12, 2016, 09:29:05 am
Thats kind of funny!

Well the quick fix is in Subs.php, and the bug should effect urls, iurls and img tags as well.  Anyway in that file search for
Code: [Select]
strpos($data, 'http://') !== 0 && strpos($data, 'https://') !== 0)
I think you will find it 6 times.  Change that to
Code: [Select]
stripos($data, 'http://') !== 0 && stripos($data, 'https://') !== 0)
and then it should stop doing what its doing.

May look at whats best there at that point, this, a substr or a simple regex, but anyway.
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: radu81 on December 12, 2016, 10:13:17 am
Tested on localhost, I confirm it works. Thanks Spuds
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: Spuds on December 12, 2016, 10:48:04 am
Glad it worked .... looking at it just a moment more, I'll probably PR something more like
Code: [Select]
if (preg_match("~^https?://~i", $data) !== 1)
since its cleaner to me.

Also in a quick test this was a bit more efficient if the selector was https (ie one preg_match was faster than two stripos or two strpos for that matter).  If the link was http then it was slightly slower (single strpos or stripos).  Of course this is one of those silly micro optimizations that should not be taken very seriously, its just for my entertainment.
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: Burke Knight on December 12, 2016, 05:09:01 pm
Quote from: radu81 – Good to know this is also an SMF bug, did you alredy reported to SMF @Burke Knight‍ ?


Really? Hahaha!!!!!
Why should I even entertain the thought of helping that vile project and it's evil Project Manager, who does not even know a quarter of their product than a 2 year old does?

His first reply to you in your report, proves it.
He's not interested in SMF, and improving it.
He's just interested in shifting the blame for things, and making it seem like every issue is user error.

Sheesh. I'll never help any SMF site, until they get smart, and kick him out.
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: emanuele on December 12, 2016, 05:45:42 pm
Please, free bashing is not really helpful to anyone.
That said, arguments that support the objection are instead always welcome:
Quote from: https://tools.ietf.org/html/rfc3986#section-3.1Although schemes are case-
   insensitive, the canonical form is lowercase and documents that
   specify schemes must do so with lowercase letters.  An implementation
   should accept uppercase letters as equivalent to lowercase in scheme
   names (e.g., allow "HTTP" as well as "http") for the sake of
   robustness but should only produce lowercase scheme names for
   consistency.
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: Spuds on December 12, 2016, 05:58:36 pm
So we add a $match to the preg and
Code: [Select]
strtolower($match[0])
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: emanuele on December 12, 2016, 07:18:38 pm
Are we so picky? lol
At the moment I did this:
https://github.com/elkarte/Elkarte/compare/development...emanuele45:protocol
to replace the protocol we'd need to first remove it?
Then maybe:
Code: [Select]
	$pattern = '/^(' . implode('|', array_map(function ($val) {return preg_quote($val, "/");}, $protocols)) . ')/i';

$found = false;
$url = preg_replace_callback($pattern, function($match) use (&$found) {
$found = true;

return strtolower($match[0]);
}, $url);

if ($found === true)
{
return $url;
}

return $protocols[0] . $url;
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: Spuds on December 12, 2016, 07:57:45 pm
QuoteAre we so picky? lol
Good point, its already ~8X slower then whats there now, no need to add more functions to that cauldron lol.

ETA:

If it were me, I'd set $protocals = array() in the function, then
Code: [Select]
	if (empty($protocols))
$pattern = '~^https?://~i';
else
$pattern = '/^(' . implode('|', array_map(function ($val) {return preg_quote($val, "/");}, $protocols)) . ')/i';
to avoid having to build $pattern when you know what it will be by default, that cuts down on the inefficiency.
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: emanuele on December 13, 2016, 03:50:43 am
Good point.

ETA: BTW, what code are you using to test efficiency? O:-)
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: radu81 on December 13, 2016, 03:27:01 pm
I don't understand much of what you two wrote above, but I'm glad to see that elkarte is having such an attention on performance. We all love fast websites ;)

OT: regarding SMF, I'm not using it, but I still read and sometimes write on sm.org forums... I did the report, it's up to their team to decide what to do. 
Title: Re: Bug with links inserted with HTTP in uppercase
Post by: Spuds on December 13, 2016, 09:26:37 pm
Quote from: emanuele – ETA: BTW, what code are you using to test efficiency? O:-)
Good old Ubench ... a version I made some minor updates to (some time back), but its still unknown w brackets program