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

crash when escaping space character #20

Open
DetachHead opened this issue Apr 30, 2024 · 2 comments
Open

crash when escaping space character #20

DetachHead opened this issue Apr 30, 2024 · 2 comments

Comments

@DetachHead
Copy link

DetachHead commented Apr 30, 2024

require('xspattern').compile("a\\ b")
Uncaught:
Error: Error parsing pattern "a\ b" at offset 1: expected "end of input" but found "\"

escaping a space is not necessary in javascript, but perfectly valid:

new RegExp("a\\ b") // no error

escaping spaces is required in python when using the re.VERBOSE flag, which strips all un-escaped whitespace:

re.compile('a b', re.VERBOSE).match('ab') # matches
re.compile('a\\ b', re.VERBOSE).match('ab') # doesn't match

my use case is that i'm constructing a regex in python using re.escape which is then passed to xspattern.compile, which is causing this crash.

@DetachHead DetachHead changed the title crash when escaping space character crash when escaping characters that don't need to be escaped Apr 30, 2024
@DetachHead DetachHead changed the title crash when escaping characters that don't need to be escaped crash when escaping space character Apr 30, 2024
@bwrrp
Copy link
Owner

bwrrp commented May 2, 2024

Hi,

While escaping spaces is allowed (and apparently sometimes required) in Python's regex syntax, it does not seem to be allowed in the the XML Schema regex syntax implemented by this library. The list of valid escapes is given here for single-character escapes and here for multi-char escapes.

As a\ b is not a valid regex, the error is expected. A version of an re.escape-like function geared toward the XML Schema regex language could definitely be a good addition to this library, so I'll leave this open as a feature request.

@DetachHead
Copy link
Author

looks like the & character has the same issue

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