Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special characters should be preserved when using a placeholder in a regexp query #1291

Closed
hubgit opened this issue Nov 7, 2023 · 2 comments

Comments

@hubgit
Copy link
Contributor

hubgit commented Nov 7, 2023

Describe the issue

When replacing text using a regexp query, with a placeholder in the replacement, special characters such as \t and \n will be replaced, when they should be preserved.

For example, in a JS console:

> '\\test'.replace(/(\\[a-z]+)/, ':$1:')
> ':\test:'

In CodeMirror, this replacement currently results in : est:.

I think this can be fixed by moving .replace(…) so it runs after .unquote(…) in the getReplacement function, I'm just not sure whether this would have any negative effects.

https://github.com/codemirror/search/blob/7a4a57e52b4af5807d195296c9933c4c7df947f5/src/search.ts#L295-L301

Browser and platform

Chrome, macOS

Reproduction link

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgoKbmV3IEVkaXRvclZpZXcoewogIGRvYzogYC8vIG9wZW4gdGhlIHNlYXJjaCBwYW5lbCwgZW5hYmxlIHRoZSByZWdleCBvcHRpb24KLy8gYW5kIHJlcGxhY2UgIihcXFxcW2Etel0rKVxcbiIgd2l0aCAiOiQxOlxcbiIKXFx0ZXN0XG5cXHRlc3RcbmAsCiAgZXh0ZW5zaW9uczogW2Jhc2ljU2V0dXBdLAogIHBhcmVudDogZG9jdW1lbnQuYm9keQp9KQo=

@hubgit
Copy link
Contributor Author

hubgit commented Nov 7, 2023

I should add that literal is set to false for these queries, as we do still want to allow matching newlines with \n in the actual query.

@marijnh
Copy link
Member

marijnh commented Nov 7, 2023

Good point, I agree that those calls should be swapped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants