.github
1 year ago
.gitignore
1 year ago
.travis.yml
2 years ago
LICENSE
3 years ago
MANIFEST.in
2 years ago
README.md
1 year ago
__init__.py
1 year ago
composer.json
3 years ago
crawler-user-agents.json
1 year ago
format.js
1 year ago
go.mod
2 years ago
go.sum
2 years ago
index.d.ts
3 years ago
main.php
3 years ago
package-lock.json
2 years ago
package.json
2 years ago
pyproject.toml
1 year ago
test_harness.py
1 year ago
test_validation.py
3 years ago
validate.go
1 year ago
validate.php
3 years ago
validate.py
2 years ago
validate_test.go
1 year ago
validate.php
31 lines
| 1 | <?php |
| 2 | // checks that the patterns work in PHP's preg_match |
| 3 | |
| 4 | $data = json_decode(file_get_contents('crawler-user-agents.json'), true); |
| 5 | |
| 6 | $patterns = array(); |
| 7 | foreach($data as $entry) { |
| 8 | $patterns[] = $entry['pattern']; |
| 9 | if (isset($entry['instances'])) { |
| 10 | foreach($entry['instances'] as $ua_example) { |
| 11 | if (!preg_match('/'.$entry['pattern'].'/', $ua_example)) { |
| 12 | throw new Exception('pb with '.$entry['pattern']); |
| 13 | } |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | // testing with a giant regexp |
| 19 | $regexp = implode('|', $patterns); |
| 20 | foreach($data as $entry) { |
| 21 | if (isset($entry['instances'])) { |
| 22 | foreach($entry['instances'] as $ua_example) { |
| 23 | if (!preg_match('/'.$regexp.'/', $ua_example)) { |
| 24 | throw new Exception('pb with '.$entry['pattern']); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | ?> |
| 31 |