Escape control characters and most whitespace in error tracebacks
- Dominant language
- Python
- Stars
- 51
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
When a ParseError is raised and printed, the pattern it tried to match is printed as well. If the pattern has control characters like `\n` or `\r`, these will get printed and make the output awkward to read.
The problem is not so bad when the only whitespace characters in the pattern are a regular space and a tab:
```pycon
>>> p = pe.compile('"a" [ \t] "b"')
>>> p.match("ab")
Traceback (most recent call last):
[...]
pe._errors.ParseError:
line 0, character 0
ab
^
ParseError: `a[\ \ ]b`
```
But when a `\r` is part of the pattern, the `ParseError` name gets overwritten:
```pycon
>>> p = pe.compile('"a" [ \t\r] "b"')
>>> p.match("ab")
Traceback (most recent call last):
[...]
pe._errors.ParseError:
line 0, character 0
ab
^
]b`seError: `a[\ \ \
```
The characters should be escaped so it looks more like this:
```
ParseError: `a[ \t\r]b`
```
Also see #59.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.