Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
sqlmap/tests/test_sqlparse.py at master · sqlmapproject/sqlmap · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
sqlmapproject
/
sqlmap
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
6.4k
Star
38.4k
Code
Issues
26
Pull requests
7
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
sqlmap
/
tests
/
test_sqlparse.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
87 lines (68 loc) · 3.65 KB
master
Breadcrumbs
sqlmap
/
tests
/
test_sqlparse.py
Copy path
Top
File metadata and controls
Code
Blame
87 lines (68 loc) · 3.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
"""
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
See the file 'LICENSE' for copying permission
SQL/string parsing helpers: field splitting and 0-depth (paren+quote aware)
scanning, query cleanup, regex extraction.
Includes regression cases for the quote-awareness bugs fixed previously.
"""
import
os
import
sys
import
unittest
sys
.
path
.
insert
(
0
,
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
from
_testutils
import
bootstrap
bootstrap
()
from
lib
.
core
.
common
import
splitFields
,
zeroDepthSearch
,
cleanQuery
,
extractRegexResult
class
TestSplitFields
(
unittest
.
TestCase
):
CASES
=
[
(
"a,b"
, [
"a"
,
"b"
]),
(
"user,password"
, [
"user"
,
"password"
]),
(
"a,b,c"
, [
"a"
,
"b"
,
"c"
]),
(
"a"
, [
"a"
]),
(
"max(a,b)"
, [
"max(a,b)"
]),
# paren-protected
(
"max(a, b),c"
, [
"max(a,b)"
,
"c"
]),
# ', ' normalized; outer split
(
"COUNT(*),name"
, [
"COUNT(*)"
,
"name"
]),
(
"f(g(x,y),z),h"
, [
"f(g(x,y),z)"
,
"h"
]),
# nested parens
(
"'a,b'"
, [
"'a,b'"
]),
# REGRESSION: comma in single-quoted literal
(
"'a,b','c|d','e&f'"
, [
"'a,b'"
,
"'c|d'"
,
"'e&f'"
]),
# REGRESSION
(
'"x,y",z'
, [
'"x,y"'
,
"z"
]),
# double-quoted literal
]
def
test_table
(
self
):
for
inp
,
expected
in
self
.
CASES
:
self
.
assertEqual
(
splitFields
(
inp
),
expected
,
msg
=
"splitFields(%r)"
%
inp
)
class
TestZeroDepthSearch
(
unittest
.
TestCase
):
def
test_quote_awareness
(
self
):
# ' FROM ' inside a literal must NOT be a clause boundary (regression)
self
.
assertEqual
(
zeroDepthSearch
(
"SELECT 'x FROM y'"
,
" FROM "
), [])
# a real FROM must be found (exactly once here)
self
.
assertEqual
(
len
(
zeroDepthSearch
(
"SELECT a FROM t"
,
" FROM "
)),
1
)
def
test_paren_awareness
(
self
):
self
.
assertEqual
(
zeroDepthSearch
(
"a(,)b,c"
,
","
), [
5
])
# only the depth-0 comma
def
test_doctest_vectors
(
self
):
q
=
"SELECT (SELECT id FROM users WHERE 2>1) AS result FROM DUAL"
hits
=
zeroDepthSearch
(
q
,
"FROM"
)
self
.
assertTrue
(
hits
,
"no depth-0 FROM found"
)
# guard: avoid a confusing IndexError
self
.
assertEqual
(
q
[
hits
[
0
]:],
"FROM DUAL"
)
# outer FROM only
s
=
"a(b; c),d;e"
hits
=
zeroDepthSearch
(
s
,
"[;, ]"
)
self
.
assertTrue
(
hits
)
self
.
assertEqual
(
s
[
hits
[
0
]:],
",d;e"
)
# char-class form
class
TestCleanQuery
(
unittest
.
TestCase
):
def
test_keyword_uppercasing
(
self
):
self
.
assertEqual
(
cleanQuery
(
"select a from t"
),
"SELECT a FROM t"
)
# mixed case keywords get uppercased; non-keyword identifiers are preserved verbatim
self
.
assertEqual
(
cleanQuery
(
"seLeCt a fRoM t"
),
"SELECT a FROM t"
)
self
.
assertEqual
(
cleanQuery
(
"SELECT 1"
),
"SELECT 1"
)
# already-upper unchanged
def
test_idempotent
(
self
):
for
q
in
[
"select a from t"
,
"SELECT 1"
,
"select x where y=1 order by z"
]:
once
=
cleanQuery
(
q
)
self
.
assertEqual
(
cleanQuery
(
once
),
once
)
# idempotence alone would pass even if cleanQuery uppercased EVERYTHING; anchor that it
# uppercases keywords but preserves the lowercase identifier
self
.
assertEqual
(
cleanQuery
(
"select a from t"
),
"SELECT a FROM t"
)
class
TestExtractRegexResult
(
unittest
.
TestCase
):
def
test_named_group
(
self
):
self
.
assertEqual
(
extractRegexResult
(
r"id=(?P<result>\d+)"
,
"id=42"
),
"42"
)
self
.
assertIsNone
(
extractRegexResult
(
r"id=(?P<result>\d+)"
,
"no match here"
))
if
__name__
==
"__main__"
:
unittest
.
main
(
verbosity
=
2
)
You can’t perform that action at this time.