From 4faf9fb87466f16f2c9894672d481dcfc5c16c5d Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Tue, 1 Dec 2020 20:46:34 +0100 Subject: [PATCH] Escape token, tokens and keyword, issue #16 --- pyleri/__init__.py | 2 +- pyleri/keyword.py | 10 +++++----- pyleri/token.py | 10 +++++----- pyleri/tokens.py | 12 +++++++----- setup.py | 2 -- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pyleri/__init__.py b/pyleri/__init__.py index 88afa25..6627023 100644 --- a/pyleri/__init__.py +++ b/pyleri/__init__.py @@ -41,4 +41,4 @@ __author__ = 'Jeroen van der Heijden' __maintainer__ = 'Jeroen van der Heijden' __email__ = 'jeroen@transceptor.technology' -__version__ = '1.3.2' +__version__ = '1.3.3' diff --git a/pyleri/keyword.py b/pyleri/keyword.py index a8b6e36..c3622d1 100644 --- a/pyleri/keyword.py +++ b/pyleri/keyword.py @@ -50,19 +50,19 @@ def _get_node_result(self, root, tree, rule, s, node): def _run_export_js(self, js_indent, indent, classes, cname): return 'Keyword(\'{}\'{})'.format( - self._keyword, + self._keyword.replace('\'', '\\\''), ', true' if self._ign_case else '') def _run_export_py(self, py_indent, indent, classes): return 'Keyword(\'{}\'{})'.format( - self._keyword, + self._keyword.replace('\'', '\\\''), ', True' if self._ign_case else '') @c_export def _run_export_c(self, c_indent, indent, enums, gid): return 'cleri_keyword({}, "{}", {})'.format( gid, - self._keyword, + self._keyword.replace('"', '\\"'), 'CLERI_CASE_INSENSITIVE' if self._ign_case else 'CLERI_CASE_SENSITIVE') @@ -70,12 +70,12 @@ def _run_export_c(self, c_indent, indent, enums, gid): def _run_export_go(self, go_indent, indent, enums, gid): return 'goleri.NewKeyword({}, "{}", {})'.format( gid, - self._keyword, + self._keyword.replace('"', '\\"'), 'true' if self._ign_case else 'false') @java_export def _run_export_java(self, c_indent, indent, enums, classes, gid): return 'new Keyword({}"{}", {})'.format( '' if gid is None else 'Ids.{}, '.format(gid), - self._keyword, + self._keyword.replace('"', '\\"'), 'true' if self._ign_case else 'false') diff --git a/pyleri/token.py b/pyleri/token.py index f698272..99a1644 100644 --- a/pyleri/token.py +++ b/pyleri/token.py @@ -29,25 +29,25 @@ def _get_node_result(self, root, tree, rule, s, node): return is_valid, node.end or node.start def _run_export_js(self, js_indent, indent, classes, cname): - return 'Token(\'{}\')'.format(self._token) + return 'Token(\'{}\')'.format(self._token.replace('\'', '\\\'')) def _run_export_py(self, py_indent, indent, classes): - return 'Token(\'{}\')'.format(self._token) + return 'Token(\'{}\')'.format(self._token.replace('\'', '\\\'')) @c_export def _run_export_c(self, js_indent, indent, enums, gid): return 'cleri_token({}, "{}")'.format( gid, - self._token) + self._token.replace('"', '\\"')) @go_export def _run_export_go(self, go_indent, indent, enums, gid): return 'goleri.NewToken({}, "{}")'.format( gid, - self._token) + self._token.replace('"', '\\"')) @java_export def _run_export_java(self, java_indent, indent, enums, classes, gid): return 'new Token({}"{}")'.format( '' if gid is None else 'Ids.{}, '.format(gid), - self._token) + self._token.replace('"', '\\"')) diff --git a/pyleri/tokens.py b/pyleri/tokens.py index a75cb62..2ed1e86 100644 --- a/pyleri/tokens.py +++ b/pyleri/tokens.py @@ -27,25 +27,27 @@ def _get_node_result(self, root, tree, rule, s, node): return False, node.start def _run_export_js(self, js_indent, indent, classes, cname): - return 'Tokens(\'{}\')'.format(' '.join(self._tokens)) + return 'Tokens(\'{}\')'.format( + ' '.join(self._tokens).replace('\'', '\\\'')) def _run_export_py(self, py_indent, indent, classes): - return 'Tokens(\'{}\')'.format(' '.join(self._tokens)) + return 'Tokens(\'{}\')'.format( + ' '.join(self._tokens).replace('\'', '\\\'')) @c_export def _run_export_c(self, c_indent, indent, enums, gid): return 'cleri_tokens({}, "{}")'.format( gid, - ' '.join(self._tokens)) + ' '.join(self._tokens).replace('"', '\\"')) @go_export def _run_export_go(self, go_indent, indent, enums, gid): return 'goleri.NewTokens({}, "{}")'.format( gid, - ' '.join(self._tokens)) + ' '.join(self._tokens).replace('"', '\\"')) @java_export def _run_export_java(self, java_indent, indent, enums, classes, gid): return 'new Tokens({}"{}")'.format( '' if gid is None else 'Ids.{}, '.format(gid), - ' '.join(self._tokens)) + ' '.join(self._tokens).replace('"', '\\"')) diff --git a/setup.py b/setup.py index a6baf7e..5395be4 100644 --- a/setup.py +++ b/setup.py @@ -4,9 +4,7 @@ python3 setup.py sdist twine upload --repository pypitest dist/pyleri-x.x.x.tar.gz - twine upload --repository pypi dist/pyleri-x.x.x.tar.gz - """ from setuptools import setup from pyleri import __version__ as version