Reject invalid escapes in strings

Fixes `invalid-escape` test.

Signed-off-by: fandehui <fandehui@xfusion.com>
This commit is contained in:
fandehui 2023-12-29 17:32:26 +08:00
parent 842522e036
commit a49e36dc11
2 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,34 @@
From 09b300acf1142fec5de429d3521c09afad0832c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sat, 27 Oct 2018 21:57:01 +0200
Subject: [PATCH] Reject invalid escapes in strings
Fixes `invalid-escape` test.
---
pytoml/parser.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pytoml/parser.py b/pytoml/parser.py
index 6d4d483..b4f7646 100644
--- a/pytoml/parser.py
+++ b/pytoml/parser.py
@@ -180,13 +180,13 @@ _ws_re = re.compile(r'[ \t]*')
def _p_ws(s):
s.expect_re(_ws_re)
-_escapes = { 'b': '\b', 'n': '\n', 'r': '\r', 't': '\t', '"': '"', '\'': '\'',
- '\\': '\\', '/': '/', 'f': '\f' }
+_escapes = { 'b': '\b', 'n': '\n', 'r': '\r', 't': '\t', '"': '"',
+ '\\': '\\', 'f': '\f' }
_basicstr_re = re.compile(r'[^"\\\000-\037]*')
_short_uni_re = re.compile(r'u([0-9a-fA-F]{4})')
_long_uni_re = re.compile(r'U([0-9a-fA-F]{8})')
-_escapes_re = re.compile('[bnrt"\'\\\\/f]')
+_escapes_re = re.compile(r'[btnfr\"\\]')
_newline_esc_re = re.compile('\n[ \t\n]*')
def _p_basicstr_content(s, content=_basicstr_re):
res = []
--
2.27.0

View File

@ -2,13 +2,14 @@
Name: python-%{github_name}
Version: 0.1.18
Release: 5
Release: 6
Summary: Parser for TOML
License: MIT
URL: https://github.com/avakar/%{github_name}
Source0: https://github.com/avakar/%{github_name}/archive/v%{version}/%{github_name}-%{version}.tar.gz
Patch0: Add-.vscode-and-.pytest_cache-to-.gitignore.patch
Patch1: Fix-datetime-serialization.patch
Patch2: Reject-invalid-escapes-in-strings.patch
BuildArch: noarch
%global my_description \
@ -44,6 +45,9 @@ BuildRequires: python3-setuptools
%{python3_sitelib}/%{github_name}/
%changelog
* Fri Dec 29 2023 fandehui <fandehui@xfusion.com> - 0.1.18-6
- Reject invalid escapes in strings
* Fri Dec 29 2023 fandehui <fandehui@xfusion.com> - 0.1.18-5
- Fix datetime serialization