Skip to content

WiP: switch e.g. html/javascript template strings with embedded escape codes to raw string#395

Draft
jonasbardino wants to merge 8 commits into
nextfrom
fix/invalid-escape-sequences-in-strings-with-explicit-raw-strings
Draft

WiP: switch e.g. html/javascript template strings with embedded escape codes to raw string#395
jonasbardino wants to merge 8 commits into
nextfrom
fix/invalid-escape-sequences-in-strings-with-explicit-raw-strings

Conversation

@jonasbardino

@jonasbardino jonasbardino commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

Switch e.g. html/javascript template strings with embedded escapes in them to raw strings like r"bla\*" in order to avoid DeprecationWarning(on python3.6+) orSyntaxError` (python3.12+).

Tools like bandit will warn about the existence of such strings when scanned so it can be used to locate all relevant occurrences in our code base.

It's important to validate that the raw string wrapping does not change the meaning of the code. They typically remove the need for one level of escaping as in

 > python
Python 3.12.3 (main, Nov  6 2025, 13:44:16) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> r'\.'
'\\.'

Integrates #609 to prevent the corresponding old lint errors in existing code. So it's best to merge that one first.

Still pending some verification that none of the updates actually change the resulting strings. Manually verified for server/*.py modules so far.

We should add unit tests to verify the correct output of the individual functions or the entire page.

@jonasbardino jonasbardino self-assigned this Dec 12, 2025
@jonasbardino jonasbardino added the WiP Work-in-Progress: any review requests do NOT mean it's ready for merge. label Jul 2, 2026
…scapes in

them to raw strings in order to avoid DeprecationWarning (on python3.6+) or
SyntaxError (python3.12+).
@jonasbardino
jonasbardino force-pushed the fix/invalid-escape-sequences-in-strings-with-explicit-raw-strings branch from 0fcccff to 5d7a987 Compare July 17, 2026 12:34
…rings to

avoid DeprecationWarning or SyntaxError when running our code or the unit tests
with recent python versions.
Now `make unittest` completes without such issues. There may be additional
cases lurking in parts of the code simply not covered by unittests yet.
…s are

used. Now checking with
`bandit -v -r mig/shared|grep 'invalid escape sequence'`
only reports an invalid escaped '\S' in the ancient `forum.py` helper which is
scheduled for retirement.
…s are

used in `mig/server/` as well . Now checking with
`bandit -v -r mig/|grep 'invalid escape sequence'`
only reports an invalid escaped '\S' in the ancient `forum.py` helper which is
scheduled for retirement.
Reimplemented the dead-ugly conditional print in `print_on_error` in an attempt
to prevent any future readers from going insane.
@jonasbardino

Copy link
Copy Markdown
Contributor Author

The final remaining lint error is a duplicate of the old one from #338.

…eparate

future branch. It is also necessary to introduce the now mandatory parenteses
currently missing in the old (py2) print statements.
…leaving

out the complex escaping to completely remove the need for r-strings there.

Further updates may be needed there as well in the future task to fix the
py2'isms like `print "bla"` without parentheses in the python version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WiP Work-in-Progress: any review requests do NOT mean it's ready for merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant