From 56b0a678adcaf6fe3bf68b4c6c85e369887d6ecc Mon Sep 17 00:00:00 2001 From: Felipe Zorzo Date: Wed, 28 Feb 2024 20:43:20 -0300 Subject: [PATCH] fix: Fix lexer to correctly handle national character literals (#181) --- .../src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt | 2 +- .../src/test/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexerTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt index 42ee46c3..ba936120 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt @@ -44,7 +44,7 @@ object PlSqlLexer { private const val CUSTOM_DELIMITER_END = "\\1" // same as the start private val STRING_LITERAL = ("(?is)(?:" - + or("?:'(?:[^']|'')*+'", // simple text literal + + or("?:n?'(?:[^']|'')*+'", // simple text literal "n?q?'" + or("?:" + g("?:" + g(CUSTOM_DELIMITER_START) + ".*?(?:" + CUSTOM_DELIMITER_END + "')"), g("?:\\(.*?\\)'"), g("?:\\[.*?\\]'"), diff --git a/zpa-core/src/test/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexerTest.kt b/zpa-core/src/test/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexerTest.kt index 11319004..3fc38ba8 100644 --- a/zpa-core/src/test/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexerTest.kt +++ b/zpa-core/src/test/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexerTest.kt @@ -61,7 +61,7 @@ class PlSqlLexerTest { @Test fun simpleNationalCharsetStringLiteral() { - assertThatIsToken("n'Test'", PlSqlTokenType.STRING_LITERAL) + assertThatIsToken("n'Test string'", PlSqlTokenType.STRING_LITERAL) } @Test