|
| 1 | +--TEST-- |
| 2 | +filter_var() and FILTER_VALIDATE_URL with different URI parsers |
| 3 | +--EXTENSIONS-- |
| 4 | +filter |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +function validateUrls(string $parserName) |
| 9 | +{ |
| 10 | + $values = [ |
| 11 | + 'http://example.com/index.html', |
| 12 | + 'http://www.example.com/index.php', |
| 13 | + 'http://www.example/img/test.png', |
| 14 | + 'http://www.example/img/dir/', |
| 15 | + 'http://www.example/img/dir', |
| 16 | + 'http://www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/', |
| 17 | + 'http://toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong.com', |
| 18 | + 'http://eauBcFReEmjLcoZwI0RuONNnwU4H9r151juCaqTI5VeIP5jcYIqhx1lh5vV00l2rTs6y7hOp7rYw42QZiq6VIzjcYrRm8gFRMk9U9Wi1grL8Mr5kLVloYLthHgyA94QK3SaXCATklxgo6XvcbXIqAGG7U0KxTr8hJJU1p2ZQ2mXHmp4DhYP8N9SRuEKzaCPcSIcW7uj21jZqBigsLsNAXEzU8SPXZjmVQVtwQATPWeWyGW4GuJhjP4Q8o0.com', |
| 19 | + 'http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com.', |
| 20 | + 'http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58R.example.com', |
| 21 | + 'http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]', |
| 22 | + 'http://[2001:db8:0:85a3:0:0:ac1f:8001]:123/me.html', |
| 23 | + 'http://[2001:db8:0:85a3::ac1f:8001]/', |
| 24 | + 'http://[::1]', |
| 25 | + 'http://cont-ains.h-yph-en-s.com', |
| 26 | + 'http://..com', |
| 27 | + 'http://a.-bc.com', |
| 28 | + 'http://ab.cd-.com', |
| 29 | + 'http://-.abc.com', |
| 30 | + 'http://abc.-.abc.com', |
| 31 | + 'http://underscore_.example.com', |
| 32 | + 'http//www.example/wrong/url/', |
| 33 | + 'http:/www.example', |
| 34 | + 'file:///tmp/test.c', |
| 35 | + 'ftp://ftp.example.com/tmp/', |
| 36 | + '/tmp/test.c', |
| 37 | + '/', |
| 38 | + 'http://', |
| 39 | + 'http:/', |
| 40 | + 'http:', |
| 41 | + 'http', |
| 42 | + '', |
| 43 | + -1, |
| 44 | + [], |
| 45 | + |
| 46 | + 'news:news.php.net', |
| 47 | + 'file://foo/bar', |
| 48 | + "http://\r\n/bar", |
| 49 | + "http://example.com:qq", |
| 50 | + "http://example.com:-2", |
| 51 | + "http://example.com:65536", |
| 52 | + "http://example.com:65537", |
| 53 | + ]; |
| 54 | + |
| 55 | + foreach ($values as $value) { |
| 56 | + var_dump(filter_var($value, FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName])); |
| 57 | + } |
| 58 | + |
| 59 | + var_dump(filter_var("qwe", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName])); |
| 60 | + var_dump(filter_var("http://qwe", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName])); |
| 61 | + var_dump(filter_var("http://", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName])); |
| 62 | + var_dump(filter_var("/tmp/test", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName])); |
| 63 | + var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName])); |
| 64 | + var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED])); |
| 65 | + var_dump(filter_var("http://www.example.com/path/at/the/server/", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED])); |
| 66 | + var_dump(filter_var("http://www.example.com/index.html", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED])); |
| 67 | + var_dump(filter_var("http://www.example.com/index.php?a=b&c=d", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED])); |
| 68 | +} |
| 69 | + |
| 70 | +echo "RFC3986:\n"; |
| 71 | +validateUrls(Uri\Rfc3986Uri::class); |
| 72 | + |
| 73 | +echo "\nWHATWG:\n"; |
| 74 | +validateUrls(Uri\WhatWgUri::class); |
| 75 | + |
| 76 | +echo "Done\n"; |
| 77 | +?> |
| 78 | +--EXPECT-- |
| 79 | +RFC3986: |
| 80 | +string(29) "http://example.com/index.html" |
| 81 | +string(32) "http://www.example.com/index.php" |
| 82 | +string(31) "http://www.example/img/test.png" |
| 83 | +string(27) "http://www.example/img/dir/" |
| 84 | +string(26) "http://www.example/img/dir" |
| 85 | +string(79) "http://www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/" |
| 86 | +string(81) "http://toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong.com" |
| 87 | +string(261) "http://eauBcFReEmjLcoZwI0RuONNnwU4H9r151juCaqTI5VeIP5jcYIqhx1lh5vV00l2rTs6y7hOp7rYw42QZiq6VIzjcYrRm8gFRMk9U9Wi1grL8Mr5kLVloYLthHgyA94QK3SaXCATklxgo6XvcbXIqAGG7U0KxTr8hJJU1p2ZQ2mXHmp4DhYP8N9SRuEKzaCPcSIcW7uj21jZqBigsLsNAXEzU8SPXZjmVQVtwQATPWeWyGW4GuJhjP4Q8o0.com" |
| 88 | +string(261) "http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com." |
| 89 | +string(83) "http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58R.example.com" |
| 90 | +string(48) "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]" |
| 91 | +string(50) "http://[2001:db8:0:85a3:0:0:ac1f:8001]:123/me.html" |
| 92 | +string(36) "http://[2001:db8:0:85a3::ac1f:8001]/" |
| 93 | +string(12) "http://[::1]" |
| 94 | +string(31) "http://cont-ains.h-yph-en-s.com" |
| 95 | +string(12) "http://..com" |
| 96 | +string(16) "http://a.-bc.com" |
| 97 | +string(17) "http://ab.cd-.com" |
| 98 | +string(16) "http://-.abc.com" |
| 99 | +string(20) "http://abc.-.abc.com" |
| 100 | +string(30) "http://underscore_.example.com" |
| 101 | +bool(false) |
| 102 | +bool(false) |
| 103 | +string(18) "file:///tmp/test.c" |
| 104 | +string(26) "ftp://ftp.example.com/tmp/" |
| 105 | +bool(false) |
| 106 | +bool(false) |
| 107 | +string(7) "http://" |
| 108 | +bool(false) |
| 109 | +bool(false) |
| 110 | +bool(false) |
| 111 | +bool(false) |
| 112 | +bool(false) |
| 113 | +bool(false) |
| 114 | +string(18) "mailto: [email protected]" |
| 115 | +string(17) "news:news.php.net" |
| 116 | +string(14) "file://foo/bar" |
| 117 | +bool(false) |
| 118 | +bool(false) |
| 119 | +bool(false) |
| 120 | +string(24) "http://example.com:65536" |
| 121 | +string(24) "http://example.com:65537" |
| 122 | +bool(false) |
| 123 | +string(10) "http://qwe" |
| 124 | +string(7) "http://" |
| 125 | +bool(false) |
| 126 | +string(22) "http://www.example.com" |
| 127 | +bool(false) |
| 128 | +string(42) "http://www.example.com/path/at/the/server/" |
| 129 | +bool(false) |
| 130 | +string(40) "http://www.example.com/index.php?a=b&c=d" |
| 131 | + |
| 132 | +WHATWG: |
| 133 | +string(29) "http://example.com/index.html" |
| 134 | +string(32) "http://www.example.com/index.php" |
| 135 | +string(31) "http://www.example/img/test.png" |
| 136 | +string(27) "http://www.example/img/dir/" |
| 137 | +string(26) "http://www.example/img/dir" |
| 138 | +string(79) "http://www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/" |
| 139 | +string(81) "http://toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong.com" |
| 140 | +string(261) "http://eauBcFReEmjLcoZwI0RuONNnwU4H9r151juCaqTI5VeIP5jcYIqhx1lh5vV00l2rTs6y7hOp7rYw42QZiq6VIzjcYrRm8gFRMk9U9Wi1grL8Mr5kLVloYLthHgyA94QK3SaXCATklxgo6XvcbXIqAGG7U0KxTr8hJJU1p2ZQ2mXHmp4DhYP8N9SRuEKzaCPcSIcW7uj21jZqBigsLsNAXEzU8SPXZjmVQVtwQATPWeWyGW4GuJhjP4Q8o0.com" |
| 141 | +string(261) "http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com." |
| 142 | +string(83) "http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58R.example.com" |
| 143 | +string(48) "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]" |
| 144 | +string(50) "http://[2001:db8:0:85a3:0:0:ac1f:8001]:123/me.html" |
| 145 | +string(36) "http://[2001:db8:0:85a3::ac1f:8001]/" |
| 146 | +string(12) "http://[::1]" |
| 147 | +string(31) "http://cont-ains.h-yph-en-s.com" |
| 148 | +string(12) "http://..com" |
| 149 | +string(16) "http://a.-bc.com" |
| 150 | +string(17) "http://ab.cd-.com" |
| 151 | +string(16) "http://-.abc.com" |
| 152 | +string(20) "http://abc.-.abc.com" |
| 153 | +string(30) "http://underscore_.example.com" |
| 154 | +bool(false) |
| 155 | +string(17) "http:/www.example" |
| 156 | +string(18) "file:///tmp/test.c" |
| 157 | +string(26) "ftp://ftp.example.com/tmp/" |
| 158 | +bool(false) |
| 159 | +bool(false) |
| 160 | +bool(false) |
| 161 | +bool(false) |
| 162 | +bool(false) |
| 163 | +bool(false) |
| 164 | +bool(false) |
| 165 | +bool(false) |
| 166 | +bool(false) |
| 167 | +string(18) "mailto: [email protected]" |
| 168 | +string(17) "news:news.php.net" |
| 169 | +string(14) "file://foo/bar" |
| 170 | +bool(false) |
| 171 | +bool(false) |
| 172 | +bool(false) |
| 173 | +bool(false) |
| 174 | +bool(false) |
| 175 | +bool(false) |
| 176 | +string(10) "http://qwe" |
| 177 | +bool(false) |
| 178 | +bool(false) |
| 179 | +string(22) "http://www.example.com" |
| 180 | +bool(false) |
| 181 | +string(42) "http://www.example.com/path/at/the/server/" |
| 182 | +bool(false) |
| 183 | +string(40) "http://www.example.com/index.php?a=b&c=d" |
| 184 | +Done |
0 commit comments