{"action":"opened","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/23307","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/23307/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/23307/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/23307/events","html_url":"https://github.com/symfony/symfony/issues/23307","id":238647677,"number":23307,"title":"[Bug] Incorrect regexp from Glob::toRegex with windows paths","user":{"login":"shude","id":10113896,"avatar_url":"https://avatars1.githubusercontent.com/u/10113896?v=3","gravatar_id":"","url":"https://api.github.com/users/shude","html_url":"https://github.com/shude","followers_url":"https://api.github.com/users/shude/followers","following_url":"https://api.github.com/users/shude/following{/other_user}","gists_url":"https://api.github.com/users/shude/gists{/gist_id}","starred_url":"https://api.github.com/users/shude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shude/subscriptions","organizations_url":"https://api.github.com/users/shude/orgs","repos_url":"https://api.github.com/users/shude/repos","events_url":"https://api.github.com/users/shude/events{/privacy}","received_events_url":"https://api.github.com/users/shude/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-06-26T19:39:48Z","updated_at":"2017-06-26T19:39:48Z","closed_at":null,"body":"| Q                | A\r\n| ---------------- | -----\r\n| Bug report?      | yes\r\n| Feature request? | no\r\n| BC Break report? | no\r\n| RFC?             | no\r\n| Symfony version  | 3.3\r\n| OS                | Windows\r\n\r\nHow to reproduce:\r\nWe have a some directory structue that looks like:\r\n\r\netc/\r\n|--dev/\r\n----| dev_conf.yaml\r\n|-- conf.yaml\r\n\r\nTry to load all yaml files from etc/:\r\n\r\n     $loader = new GlobFileLoader(new FileLocator());\r\n\r\n     $collections = $loader->load(\"path_to/etc/**/*.{php,xml,yaml,yml}\",\"glob\");\r\n     var_dump($collections);\r\n\r\nIn this case we have a trouble in Windows Paths when using ``` /**/ ``` wildcard.\r\nLoader loads nothing. Let's take a look at Config/Resources/GlobResource::getIterator()\r\n```\r\n$regex = Glob::toRegex($this->pattern);\r\n// ...\r\nif (preg_match($regex, substr($path, $prefixLen)) && $info->isFile()) {\r\n        yield $path => $info;\r\n}\r\n```\r\nWe have a ```#^(?=[^\\.])/(?:(?=[^\\.])[^/]++/)*(?=[^\\.])[^/]*\\.(php|xml|yaml|yml)$#``` regex \r\nfor ```'/**/*.{php,xml,yaml,yml}'```  pattern.\r\n\r\nBut $path in Windows contains a backslashes instead of slashes and preg_match always not matching.\r\n\r\nTo fix this we can modify Glob::toRegex() to something like this:\r\n```\r\n//Line 73\r\n$car = (DIRECTORY_SEPARATOR === '/') ? '/(?:'.$car.')*' : '\\\\\\\\(?:'.$car.')*';\r\n```\r\n\r\nAnother way is to use str_replace before preg_match in  Config/Resources/GlobResource::getIterator():\r\n```\r\n$regex = Glob::toRegex($this->pattern);\r\n// ...\r\n$path = str_replace(\"\\\\\",\"/\",$path);\r\nif (preg_match($regex, substr($path, $prefixLen)) && $info->isFile()) {\r\n        yield $path => $info;\r\n}\r\n```"}}
{"actor":{"display_login":"shude"}}