Skip to main content
Topic: Bug with links inserted with HTTP in uppercase (Read 2929 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Bug with links inserted with HTTP in uppercase

Reply #1

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

Re: Bug with links inserted with HTTP in uppercase

Reply #2

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
Last Edit: December 12, 2016, 08:51:32 am by radu81
sorry for my bad english

Re: Bug with links inserted with HTTP in uppercase

Reply #3

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.

Re: Bug with links inserted with HTTP in uppercase

Reply #4

Tested on localhost, I confirm it works. Thanks Spuds
Last Edit: December 12, 2016, 04:33:13 pm by radu81
sorry for my bad english

Re: Bug with links inserted with HTTP in uppercase

Reply #5

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.

Re: Bug with links inserted with HTTP in uppercase

Reply #6

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.

Re: Bug with links inserted with HTTP in uppercase

Reply #7

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.
Bugs creator.
Features destroyer.
Template killer.

Re: Bug with links inserted with HTTP in uppercase

Reply #8

So we add a $match to the preg and
Code: [Select]
strtolower($match[0])

Re: Bug with links inserted with HTTP in uppercase

Reply #9

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;
Bugs creator.
Features destroyer.
Template killer.

Re: Bug with links inserted with HTTP in uppercase

Reply #10

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.
Last Edit: December 12, 2016, 08:36:43 pm by Spuds

Re: Bug with links inserted with HTTP in uppercase

Reply #11

Good point.

ETA: BTW, what code are you using to test efficiency? O:-)
Bugs creator.
Features destroyer.
Template killer.

Re: Bug with links inserted with HTTP in uppercase

Reply #12

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. 
sorry for my bad english

 

Re: Bug with links inserted with HTTP in uppercase

Reply #13

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