{"action":"created","issue":{"url":"https://api.github.com/repos/giakki/uncss/issues/346","repository_url":"https://api.github.com/repos/giakki/uncss","labels_url":"https://api.github.com/repos/giakki/uncss/issues/346/labels{/name}","comments_url":"https://api.github.com/repos/giakki/uncss/issues/346/comments","events_url":"https://api.github.com/repos/giakki/uncss/issues/346/events","html_url":"https://github.com/giakki/uncss/pull/346","id":276856269,"number":346,"title":"Fix regression with dePseudify() if there are multiple pseudos that are to be ignored","user":{"login":"corpulentcoffee","id":3958448,"avatar_url":"https://avatars2.githubusercontent.com/u/3958448?v=4","gravatar_id":"","url":"https://api.github.com/users/corpulentcoffee","html_url":"https://github.com/corpulentcoffee","followers_url":"https://api.github.com/users/corpulentcoffee/followers","following_url":"https://api.github.com/users/corpulentcoffee/following{/other_user}","gists_url":"https://api.github.com/users/corpulentcoffee/gists{/gist_id}","starred_url":"https://api.github.com/users/corpulentcoffee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corpulentcoffee/subscriptions","organizations_url":"https://api.github.com/users/corpulentcoffee/orgs","repos_url":"https://api.github.com/users/corpulentcoffee/repos","events_url":"https://api.github.com/users/corpulentcoffee/events{/privacy}","received_events_url":"https://api.github.com/users/corpulentcoffee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-26T21:02:42Z","updated_at":"2017-11-26T21:19:52Z","closed_at":"2017-11-26T21:19:15Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/giakki/uncss/pulls/346","html_url":"https://github.com/giakki/uncss/pull/346","diff_url":"https://github.com/giakki/uncss/pull/346.diff","patch_url":"https://github.com/giakki/uncss/pull/346.patch"},"body":"Between 0.15.0 and 0.16.0, `dePseudify()` seemed to start mishandling selectors that have multiple pseudos, which isn't a case well-represented in the test suite but does occur in the wild (e.g. in Bootstrap 4).\r\n\r\nI'm including here a failing test and a possible fix.\r\n\r\n---\r\n\r\nOn 0.15.0:\r\n\r\n```\r\n$ echo '<p class=\"used\">Hi</p>' | ./bin/uncss --raw '.used { color: red } .unused:visited::before { content: \"a\" }'\r\n.used { color: red }\r\n```\r\n\r\nOn master / 0.16.0:\r\n\r\n```\r\n$ echo '<p class=\"used\">Hi</p>' | ./bin/uncss --raw '.used { color: red } .unused:visited::before { content: \"a\" }'\r\n.used { color: red } .unused:visited::before { content: \"a\" }\r\n```\r\n\r\nI bisected this to 0170fe1a843c7c6d90c89647ece20c80558b141f (#345), which I think is the culprit.\r\n\r\nThat `pseudosRegex = new RegExp('([^\\\\\\\\])(' + ignoredPseudos.join('|') + ')', 'g')` produces weird results if you have multiple pseudos hanging off a selector, e.g.:\r\n\r\n```\r\n$ node\r\n> ignoredPseudos = [ . . . ]\r\n[ . . . ]\r\n> pseudosRegex = new RegExp('([^\\\\\\\\])(' + ignoredPseudos.join('|') + ')', 'g')\r\n/([^\\\\])(:link|:visited|:hover|:active|:focus|:enabled|:disabled|:checked|:indeterminate|:required|:invalid|:valid|::first-line|::first-letter|::selection|::before|::after|:target|:before|:after|::?-(?:moz|ms|webkit|o)-[a-z0-9-]+)/g\r\n> 'a:visited'.replace(pseudosRegex, '$1')\r\n'a'\r\n> 'a::before'.replace(pseudosRegex, '$1')\r\n'a'\r\n> 'a:visited:hover'.replace(pseudosRegex, '$1')\r\n'a:hover'\r\n> 'a:visited::before'.replace(pseudosRegex, '$1')\r\n'a:'\r\n```\r\n\r\nI *think* if we just give the pseudo group a quantifier instead of trying to use the `g` flag from the old regex, we would get what we want (i.e. replace on any non-slash character followed by one *or more* pseudos):\r\n\r\n```\r\n> pseudosRegex = new RegExp('([^\\\\\\\\])(' + ignoredPseudos.join('|') + ')+')\r\n/([^\\\\])(:link|:visited|:hover|:active|:focus|:enabled|:disabled|:checked|:indeterminate|:required|:invalid|:valid|::first-line|::first-letter|::selection|::before|::after|:target|:before|:after|::?-(?:moz|ms|webkit|o)-[a-z0-9-]+)+/\r\n> 'a:visited'.replace(pseudosRegex, '$1')\r\n'a'\r\n> 'a::before'.replace(pseudosRegex, '$1')\r\n'a'\r\n> 'a:visited:hover'.replace(pseudosRegex, '$1')\r\n'a'\r\n> 'a:visited::before'.replace(pseudosRegex, '$1')\r\n'a'\r\n```\r\n\r\nIt should also still work for the original \"escaped\" case the original change wanted to accomplished:\r\n\r\n```\r\n> '.sm\\\\:hover\\\\:font-hairline:hover'.replace(pseudosRegex, '$1')\r\n'.sm\\\\:hover\\\\:font-hairline'\r\n> '.sm\\\\:hover\\\\:font-hairline:hover::before'.replace(pseudosRegex, '$1')\r\n'.sm\\\\:hover\\\\:font-hairline'\r\n```\r\n\r\nIt also seems to work for at least what is present in today's test suite."},"comment":{"url":"https://api.github.com/repos/giakki/uncss/issues/comments/347039230","html_url":"https://github.com/giakki/uncss/pull/346#issuecomment-347039230","issue_url":"https://api.github.com/repos/giakki/uncss/issues/346","id":347039230,"user":{"login":"mikelambert","id":7953259,"avatar_url":"https://avatars1.githubusercontent.com/u/7953259?v=4","gravatar_id":"","url":"https://api.github.com/users/mikelambert","html_url":"https://github.com/mikelambert","followers_url":"https://api.github.com/users/mikelambert/followers","following_url":"https://api.github.com/users/mikelambert/following{/other_user}","gists_url":"https://api.github.com/users/mikelambert/gists{/gist_id}","starred_url":"https://api.github.com/users/mikelambert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikelambert/subscriptions","organizations_url":"https://api.github.com/users/mikelambert/orgs","repos_url":"https://api.github.com/users/mikelambert/repos","events_url":"https://api.github.com/users/mikelambert/events{/privacy}","received_events_url":"https://api.github.com/users/mikelambert/received_events","type":"User","site_admin":false},"created_at":"2017-11-26T21:19:52Z","updated_at":"2017-11-26T21:19:52Z","author_association":"COLLABORATOR","body":"Released as 0.16.1."}}
{"actor":{"display_login":"mikelambert"}}