Last active
December 14, 2015 02:49
-
-
Save mrclay/5016415 to your computer and use it in GitHub Desktop.
Elgg: Analyze a URL... moved to https://github.com/mrclay/elgg-url-sniffer/blob/master/Url.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This has been moved to a GitHub project: | |
* | |
* @link https://github.com/mrclay/elgg-url-sniffer | |
*/ |
i noticed that my plugin that uses this gist was totally failing to return any data from the analyze function.
debugging the issue i see that the regex being used here is broken:
if (!preg_match('~^(https?)\\://([^/]+)(/[^\\?]*)~', $url, $m))
if i test this using my handy regex tester tool (https://regex101.com/) i notice two apparent problems:
- the pair of backslashes that follow the https? capturing group appear to serve no purpose and will cause the process to never return a url.
- if i remove those backslashes and use a test url that doesn't have a path following the domain name, then nothing is returned.
if i remove the backslashes and use a url that does have a path (after the domain) then it appears to work ok.
why are those slashes in there? won't they always stop the code from working properly? (at all)
The regex tester is not PHP. In PHP the literal, '\\'
represents the string \
. And in PHP's PCRE patterns, an escape is actually needed before :
. There may be a bug, but that's not it.
This class should go in its own project...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there are some url which goes by username
http://ss.localhost/blog/owner/user1