From ce9c6fa4978eb8a2892ab8beb89bc19b69cc50cb Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 4 May 2022 10:21:45 +0200 Subject: [PATCH] Qute - fix string LiteralSupport --- .../core/src/main/java/io/quarkus/qute/LiteralSupport.java | 4 ++-- .../src/test/java/io/quarkus/qute/LiteralSupportTest.java | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/independent-projects/qute/core/src/main/java/io/quarkus/qute/LiteralSupport.java b/independent-projects/qute/core/src/main/java/io/quarkus/qute/LiteralSupport.java index 5b77b0765f1d2..79f686bd53b77 100644 --- a/independent-projects/qute/core/src/main/java/io/quarkus/qute/LiteralSupport.java +++ b/independent-projects/qute/core/src/main/java/io/quarkus/qute/LiteralSupport.java @@ -22,7 +22,8 @@ static Object getLiteralValue(String literal) { if (literal == null || literal.isEmpty()) { return value; } - if (isStringLiteralSeparator(literal.charAt(0))) { + char firstChar = literal.charAt(0); + if (isStringLiteralSeparator(firstChar) && literal.charAt(literal.length() - 1) == firstChar) { value = literal.substring(1, literal.length() - 1); } else if (literal.equals("true")) { value = Boolean.TRUE; @@ -31,7 +32,6 @@ static Object getLiteralValue(String literal) { } else if (literal.equals("null")) { value = null; } else { - char firstChar = literal.charAt(0); if (Character.isDigit(firstChar) || firstChar == '-' || firstChar == '+') { if (INTEGER_LITERAL_PATTERN.matcher(literal).matches()) { try { diff --git a/independent-projects/qute/core/src/test/java/io/quarkus/qute/LiteralSupportTest.java b/independent-projects/qute/core/src/test/java/io/quarkus/qute/LiteralSupportTest.java index 673d501467d9e..38eb2a3bb854a 100644 --- a/independent-projects/qute/core/src/test/java/io/quarkus/qute/LiteralSupportTest.java +++ b/independent-projects/qute/core/src/test/java/io/quarkus/qute/LiteralSupportTest.java @@ -48,4 +48,10 @@ public void testLiteralsInTemplate() { assertEquals("OK", engine.parse("{#if 'foo' == false}NOK{#else}OK{/if}").render()); } + @Test + public void testNonLiteral() { + assertEquals(Results.NotFound.EMPTY, LiteralSupport.getLiteralValue("'foo'.ping()")); + assertEquals(Results.NotFound.EMPTY, LiteralSupport.getLiteralValue("foo.bar")); + } + }