{"action":"created","issue":{"url":"https://api.github.com/repos/benjamingr/RegExp.escape/issues/29","labels_url":"https://api.github.com/repos/benjamingr/RegExp.escape/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/benjamingr/RegExp.escape/issues/29/comments","events_url":"https://api.github.com/repos/benjamingr/RegExp.escape/issues/29/events","html_url":"https://github.com/benjamingr/RegExp.escape/issues/29","id":89754641,"number":29,"title":"Readability vs Context-Sensitive Validity","user":{"login":"benjamingr","id":1315533,"avatar_url":"https://avatars.githubusercontent.com/u/1315533?v=3","gravatar_id":"","url":"https://api.github.com/users/benjamingr","html_url":"https://github.com/benjamingr","followers_url":"https://api.github.com/users/benjamingr/followers","following_url":"https://api.github.com/users/benjamingr/following{/other_user}","gists_url":"https://api.github.com/users/benjamingr/gists{/gist_id}","starred_url":"https://api.github.com/users/benjamingr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjamingr/subscriptions","organizations_url":"https://api.github.com/users/benjamingr/orgs","repos_url":"https://api.github.com/users/benjamingr/repos","events_url":"https://api.github.com/users/benjamingr/events{/privacy}","received_events_url":"https://api.github.com/users/benjamingr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/benjamingr/RegExp.escape/labels/discussion%20appreciated","name":"discussion appreciated","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":32,"created_at":"2015-06-20T11:01:22Z","updated_at":"2015-06-29T01:03:28Z","closed_at":null,"body":"Currently I see two opposites: \r\n\r\n - **Minimal and readable output** - We provide an implementation that only escapes what it must via `RegExp.escape` to support passing in a context-free way to the `RegExp` constructor. This means dropping `]` and `}` from the escaped set and telling people that they should be aware of context. This would provide a very readable output.\r\n - **Maximal and safe** - We provide an implementation that deals with context and is context sensitive, we additionally cater for eval cases and returns of regular expressions from the server. This would provide a much less readable but safer RegExp.  Doing this would require escaping numerics to literals to avoid capturing groups as @nikic points out, escaping `/` to allow eval** as @allenwb has suggested and escaping capturing group identifiers `:` and `!`. \r\n\r\nIt sounds like more people tend to prefer the latter, I'm not convinced because of lacking usage data indicating that the problems it solves happen in real code (data indicates otherwise) but a single counter-example would go a long way to convince me that this is a problem we need to address. I'm very tempted by the safety guarantees it provides for context sensitivity.\r\n\r\n* Escaping everything was ruled out as every single system that did it moved away from it. \r\n\r\n** but not whitespace as there is no ״ignore whitespace mode\" in JS."},"comment":{"url":"https://api.github.com/repos/benjamingr/RegExp.escape/issues/comments/116365648","html_url":"https://github.com/benjamingr/RegExp.escape/issues/29#issuecomment-116365648","issue_url":"https://api.github.com/repos/benjamingr/RegExp.escape/issues/29","id":116365648,"user":{"login":"minitech","id":1145425,"avatar_url":"https://avatars.githubusercontent.com/u/1145425?v=3","gravatar_id":"","url":"https://api.github.com/users/minitech","html_url":"https://github.com/minitech","followers_url":"https://api.github.com/users/minitech/followers","following_url":"https://api.github.com/users/minitech/following{/other_user}","gists_url":"https://api.github.com/users/minitech/gists{/gist_id}","starred_url":"https://api.github.com/users/minitech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minitech/subscriptions","organizations_url":"https://api.github.com/users/minitech/orgs","repos_url":"https://api.github.com/users/minitech/repos","events_url":"https://api.github.com/users/minitech/events{/privacy}","received_events_url":"https://api.github.com/users/minitech/received_events","type":"User","site_admin":false},"created_at":"2015-06-29T01:03:28Z","updated_at":"2015-06-29T01:03:28Z","body":"By that definition, wouldn’t the `\\uxxx` case apply?"}}