{"action":"created","issue":{"url":"https://api.github.com/repos/msaari/relevanssi/issues/7","repository_url":"https://api.github.com/repos/msaari/relevanssi","labels_url":"https://api.github.com/repos/msaari/relevanssi/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/msaari/relevanssi/issues/7/comments","events_url":"https://api.github.com/repos/msaari/relevanssi/issues/7/events","html_url":"https://github.com/msaari/relevanssi/issues/7","id":312564231,"number":7,"title":"PHP Warning:  preg_match(): Null byte in regex","user":{"login":"tomdxw","id":2256130,"avatar_url":"https://avatars1.githubusercontent.com/u/2256130?v=4","gravatar_id":"","url":"https://api.github.com/users/tomdxw","html_url":"https://github.com/tomdxw","followers_url":"https://api.github.com/users/tomdxw/followers","following_url":"https://api.github.com/users/tomdxw/following{/other_user}","gists_url":"https://api.github.com/users/tomdxw/gists{/gist_id}","starred_url":"https://api.github.com/users/tomdxw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomdxw/subscriptions","organizations_url":"https://api.github.com/users/tomdxw/orgs","repos_url":"https://api.github.com/users/tomdxw/repos","events_url":"https://api.github.com/users/tomdxw/events{/privacy}","received_events_url":"https://api.github.com/users/tomdxw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-04-09T14:54:00Z","updated_at":"2018-04-10T11:56:10Z","closed_at":null,"author_association":"NONE","body":"The use of `stripslashes` causes NULL bytes to appear in text. When this text is fed into `preg_match` it causes warnings. Example:\r\n\r\n```\r\nMar 14 16:59:10 ip-10-36-94-105 apache2[6306]: PHP Warning:  preg_match(): Null byte in regex in /.../wp-content/plugins/relevanssi-premium/lib/excerpts-highlights.php on line 525\r\nMar 14 16:59:10 ip-10-36-94-105 apache2[6306]: PHP Warning:  preg_match(): Null byte in regex in /.../wp-content/plugins/relevanssi-premium/lib/excerpts-highlights.php on line 529\r\n```\r\n\r\nI wasn't able to reproduce the warnings, but I was able to show that null bytes get added (in both `relevanssi` and `relevanssi-premium`). Steps to reproduce:\r\n\r\n- Activate `relevanssi` (or `relevanssi-premium`)\r\n- Edit `lib/common.php`: Add `echo json_encode($string);` after this line: `function relevanssi_tokenize( $string, $remove_stops = true, $min_word_length = -1 ) {`\r\n- Search for `hello\\\\0world`: i.e. `http://localhost/?s=hello%5C%5C0world`\r\n- `\"hello\\\\0world\"\"hello\\u0000world\"` will appear on the page. `\\u0000` is the JSON-encoded NULL byte. In some circumstances this string is passed to `preg_match`, which causes warnings.\r\n\r\nThis happens because the `stripslashes` function not only strips slashes, it also replaces `\\0` with a NULL byte. This feature is undocumented, you can see it here in PHP's source: https://github.com/php/php-src/blob/php-7.2.3/ext/standard/string.c#L3616-L3651"},"comment":{"url":"https://api.github.com/repos/msaari/relevanssi/issues/comments/380072410","html_url":"https://github.com/msaari/relevanssi/issues/7#issuecomment-380072410","issue_url":"https://api.github.com/repos/msaari/relevanssi/issues/7","id":380072410,"user":{"login":"msaari","id":6630010,"avatar_url":"https://avatars3.githubusercontent.com/u/6630010?v=4","gravatar_id":"","url":"https://api.github.com/users/msaari","html_url":"https://github.com/msaari","followers_url":"https://api.github.com/users/msaari/followers","following_url":"https://api.github.com/users/msaari/following{/other_user}","gists_url":"https://api.github.com/users/msaari/gists{/gist_id}","starred_url":"https://api.github.com/users/msaari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msaari/subscriptions","organizations_url":"https://api.github.com/users/msaari/orgs","repos_url":"https://api.github.com/users/msaari/repos","events_url":"https://api.github.com/users/msaari/events{/privacy}","received_events_url":"https://api.github.com/users/msaari/received_events","type":"User","site_admin":false},"created_at":"2018-04-10T11:56:09Z","updated_at":"2018-04-10T11:56:09Z","author_association":"OWNER","body":"The current version of Premium is 2.1.3, and doesn't have that bit of code at all. The current code is the same as in the free version now. So, it may have null bytes in string, but the error message won't happen."}}
{"actor":{"display_login":"msaari"}}