-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qute: ignore template files that contain whitespace in its name
- resolves #42761
- Loading branch information
Showing
10 changed files
with
122 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../test/java/io/quarkus/qute/deployment/identifiers/InvalidTemplateFileNameIgnoredTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.qute.deployment.identifiers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.logging.LogRecord; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.Engine; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class InvalidTemplateFileNameIgnoredTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addAsResource(new StringAsset( | ||
"ignored"), | ||
"templates/foo o.txt")) | ||
.setLogRecordPredicate(log -> log.getLoggerName().contains("QuteProcessor")) | ||
.assertLogRecords(records -> { | ||
for (LogRecord r : records) { | ||
if (r.getMessage().startsWith("Invalid file name detected")) { | ||
return; | ||
} | ||
} | ||
fail(); | ||
}); | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Test | ||
public void testTemplateFileIgnored() { | ||
assertFalse(engine.isTemplateLoaded("foo o.txt")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
independent-projects/qute/core/src/main/java/io/quarkus/qute/Identifiers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.qute; | ||
|
||
public final class Identifiers { | ||
|
||
/** | ||
* A valid identifier is a sequence of non-whitespace characters. | ||
* | ||
* @param value | ||
* @return {@code true} if the value represents a valid identifier, {@code false} otherwise | ||
*/ | ||
public static boolean isValid(String value) { | ||
if (value == null || value.isBlank()) { | ||
return false; | ||
} | ||
int offset = 0; | ||
int length = value.length(); | ||
while (offset < length) { | ||
int c = value.codePointAt(offset); | ||
if (!Character.isWhitespace(c)) { | ||
offset += Character.charCount(c); | ||
continue; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
independent-projects/qute/core/src/test/java/io/quarkus/qute/IdentifiersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.qute; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class IdentifiersTest { | ||
|
||
@Test | ||
public void testIsValid() { | ||
assertTrue(Identifiers.isValid("foo")); | ||
assertTrue(Identifiers.isValid("foo-bar")); | ||
assertTrue(Identifiers.isValid("fíí_")); | ||
assertFalse(Identifiers.isValid("foo bar")); | ||
assertFalse(Identifiers.isValid("")); | ||
assertFalse(Identifiers.isValid(" ")); | ||
assertTrue(Identifiers.isValid("%ů=")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters