Skip to content

Use raw strings for regular expressions in asvs.py - #3450

Merged
tghosth merged 2 commits into
OWASP:masterfrom
andretorresdg:raw-regex-strings
Nov 27, 2026
Merged

tghosth merged 2 commits into
OWASP:masterfrom
andretorresdg:raw-regex-strings

Conversation

@andretorresdg

Copy link
Copy Markdown
Contributor

This Pull Request relates to issue #... (none yet; this is a small bug fix in the export tooling, see CONTRIBUTING "Typos and bug fixes may be exceptions". Happy to open an issue first if preferred.)

What

5.0/tools/asvs.py builds several regular expressions from normal (non-raw) string literals that contain \d, \s, \w, \* and \|. Since Python 3.12 every run of the export tool prints a SyntaxWarning: invalid escape sequence for each of them (8 warnings), and Python has announced that these will eventually become a SyntaxError. The Docker image builds on alpine:3, which ships Python 3.12+, so the warnings show up in document builds today.

This PR adds the r prefix to the affected literals (version, filename, chapter heading, section heading and requirement regexes). No pattern changes meaning; the existing [^\n] in two of them is equivalent in raw and non-raw form.

4.0/tools/asvs.py has the same 8 warnings. I left it unchanged because CONTRIBUTING says the 4.0 folder is frozen at 4.0.3.

How I tested

  • python3 -W error compile of asvs.py: fails before (SyntaxError: invalid escape sequence '\d'), passes after.
  • python tools/export.py --language en for every working --format (json, json_flat, xml, csv, cdx_json, raw, json_xl, json_legacy, json_flat_legacy, csv_legacy, xml_legacy): output byte-identical before and after (cdx_json compared without its random serialNumber/timestamp).
  • --verify-only still reports 345 requirements for en.
  • Ran the old and new tool against every language folder on the v5.0.0 branch (en, pt, fa, zh-cn, ko, tr, ru, fr, id, pl) for json/csv/xml/json_flat_legacy: identical output.

Python 3.12+ emits a SyntaxWarning for invalid escape sequences such
as '\d', '\s' and '\*' in regular string literals, and this is planned
to become a SyntaxError in a future Python version. Switch the affected
regex literals to raw strings. The compiled patterns are unchanged.
@elarlang
elarlang requested a review from tghosth November 26, 2026 18:55
@tghosth
tghosth merged commit d4f51a1 into OWASP:master Nov 27, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants