Skip to content

Commit 9c46564

Browse files
committed
Fix: Update regex matching to handle proper class escaping
On Python 3.12 it's throwing compile warnings on the regex compiles: ``` spdx/verify-spdx-headers:8: SyntaxWarning: invalid escape sequence '\s' SPDX = re.compile(f'SPDX-License-Identifier:\s+({SLUG.pattern})') spdx/verify-spdx-headers:21: SyntaxWarning: invalid escape sequence '\s' pattern = f"^{init}\s*{SPDX.pattern}\s*{fini}\\s*$" spdx/verify-spdx-headers:21: SyntaxWarning: invalid escape sequence '\s' pattern = f"^{init}\s*{SPDX.pattern}\s*{fini}\s*$" ``` This escapes the the '\s' to be '\\s' instead as that is compliant, seems to compile correctly, and makes the warning go away. Quick checking on my own repos seemed to not break anything. Signed-off-by: John 'Warthog9' Hawley <[email protected]>
1 parent 0dcb2ab commit 9c46564

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

verify-spdx-headers

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import os
55
import re
66

77
SLUG = re.compile('[a-zA-Z0-9.-]+')
8-
SPDX = re.compile(f'SPDX-License-Identifier:\s+({SLUG.pattern})')
8+
SPDX = re.compile(f'SPDX-License-Identifier:\\s+({SLUG.pattern})')
99

1010
class Language:
1111
def __init__(self, *comments, shebang=False):
@@ -18,7 +18,7 @@ class Language:
1818
if isinstance(comment, tuple):
1919
(init, fini) = comment
2020

21-
pattern = f"^{init}\s*{SPDX.pattern}\s*{fini}\s*$"
21+
pattern = f"^{init}\\s*{SPDX.pattern}\\s*{fini}\\s*$"
2222
self.__match.append(re.compile(pattern))
2323

2424
def license(self, path):

0 commit comments

Comments
 (0)