Skip to content

avoid quadratic quote stripping in MultiPartName.unquote - #2858

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:multipartname-unquote-linear
Oct 25, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:multipartname-unquote-linear

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

MultiPartName.unquote strips identifier quotes with ^["\[]+|["]]+$, and Table.setName and Column.setName call it whenever a name contains a dot, so it runs on identifiers straight out of CCJSqlParserUtil.parse. The trailing alternative has no left anchor, so replaceAll retries it at every offset inside a run of quote characters, and each attempt consumes the rest of the run before failing on $. A quoted identifier can legally hold any number of doubled "" escapes, which makes that run as long as the caller wants: parsing SELECT * FROM "a""""...""".b" takes 440 ms with 10k quotes, 3.9 s with 20k, and hits the parser timeout at 40k, while the same statements parse in under 10 ms with this change. I found it while looking for other regexes applied to token images after the earlier hint and server-name fixes. unquote and isQuoted now scan the leading and trailing quote characters directly, with the same character sets and the same leading-then-trailing order, so results do not change; LEADING_TRAILING_QUOTES_PATTERN stays because it is a public constant. The new tests compare both methods against the old pattern on a set of edge cases and parse the crafted statement under a 2 second preemptive timeout.

@manticore-projects
manticore-projects merged commit c1c2755 into JSQLParser:master Oct 25, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants