Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
5ab0bb6f
Commit
5ab0bb6f
authored
1 year ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
FIX: add quote character to escaped characters
parent
924c4d29
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!130
Release v0.14.0
Pipeline
#47103
passed
1 year ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/linkahead/utils/escape.py
+36
-6
36 additions, 6 deletions
src/linkahead/utils/escape.py
unittests/test_utils.py
+4
-1
4 additions, 1 deletion
unittests/test_utils.py
with
40 additions
and
7 deletions
src/linkahead/utils/escape.py
+
36
−
6
View file @
5ab0bb6f
...
...
@@ -19,13 +19,15 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import
warnings
def
escape_quoted_text
(
text
:
str
)
->
str
:
"""
The characters ``
\\
`` and ``*`` need to be escaped if used in quoted expressions in the query
language.
This function return the given string where the characters ``
\\
`` and ``*`` are escaped by
a ``
\\
``.
def
escape_squoted_text
(
text
:
str
)
->
str
:
"""
The characters ``
\\
``, ``*`` and ``
'
`` need to be escaped if used in single quoted
expressions in the query language.
This function returns the given string where the characters ``
\\
``, ``
'
`` and ``*`` are
escaped by a ``
\\
``.
Parameters
----------
...
...
@@ -37,4 +39,32 @@ def escape_quoted_text(text: str) -> str:
str
The escaped text
"""
return
text
.
replace
(
'
\\
'
,
r
'
\\
'
).
replace
(
'
*
'
,
r
'
\*
'
)
return
text
.
replace
(
'
\\
'
,
r
'
\\
'
).
replace
(
"'"
,
"
\\
'"
).
replace
(
'
*
'
,
r
'
\*
'
)
def
escape_dquoted_text
(
text
:
str
)
->
str
:
"""
The characters ``
\\
``, ``*`` and ``
"
`` need to be escaped if used in double quoted
expressions in the query language.
This function returns the given string where the characters ``
\\
``, ``
"
`` and ``*`` are
escaped by a ``
\\
``.
Parameters
----------
text : str
The text to be escaped
Returns
-------
str
The escaped text
"""
return
text
.
replace
(
'
\\
'
,
r
'
\\
'
).
replace
(
'"'
,
'
\\
"'
).
replace
(
'
*
'
,
r
'
\*
'
)
def
escape_quoted_text
(
text
:
str
)
->
str
:
"""
Please use escape_squoted_text or escape_dquoted_text
"""
warnings
.
warn
(
"
Please use escape_squoted_text or escape_dquoted_text
"
,
DeprecationWarning
)
return
escape_squoted_text
(
text
)
This diff is collapsed.
Click to expand it.
unittests/test_utils.py
+
4
−
1
View file @
5ab0bb6f
...
...
@@ -25,7 +25,8 @@
from
__future__
import
unicode_literals
from
linkahead.common.utils
import
xml2str
from
linkahead.utils.escape
import
escape_quoted_text
from
linkahead.utils.escape
import
(
escape_dquoted_text
,
escape_quoted_text
,
escape_squoted_text
)
from
lxml.etree
import
Element
...
...
@@ -41,3 +42,5 @@ def test_escape_quoted_text():
assert
escape_quoted_text
(
"
bl
\\
a
"
)
==
"
bl
\\\\
a
"
assert
escape_quoted_text
(
"
bl*a
"
)
==
"
bl
\\
*a
"
assert
escape_quoted_text
(
"
bl*ab
\\\\
lab
\\
*labla
"
)
==
"
bl
\\
*ab
\\\\\\\\
lab
\\\\\\
*labla
"
assert
escape_squoted_text
(
"
bl
'
a
"
)
==
"
bl
\\
'
a
"
assert
escape_dquoted_text
(
'
bl
"
a
'
)
==
'
bl
\\
"
a
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment