Package org.apache.juneau.bct.assertions
Class InlineScriptSafety
java.lang.Object
org.apache.juneau.bct.assertions.InlineScriptSafety
Guards shipped resources against a literal closing script tag (
</script, matched case-insensitively).
Host pages may inline JavaScript or CSS resources into an HTML <script> block. The HTML parser ends that
block at the first closing script tag it sees, even one inside a comment or string, which silently truncates the
rest of the resource. Nothing fails loudly, so this check names each offending file and line instead.
Example:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertNoScriptCloseTag(Class<?> anchor, String resource, String... extensions) Asserts that no resource beside the specified anchor resource contains a closing script tag.findCloseTags(String name, String text) Finds each line of the specified text containing a closing script tag.listResources(Class<?> anchor, String resource, String... extensions) Lists the files in the directory containing the specified resource that end with one of the specified suffixes.
-
Method Details
-
assertNoScriptCloseTag
public static void assertNoScriptCloseTag(Class<?> anchor, String resource, String... extensions) throws IOException Asserts that no resource beside the specified anchor resource contains a closing script tag.The directory is located through the classpath, so the resources must be on the file system (not in a jar).
- Parameters:
anchor- Class used to resolveresource .resource- Resource path, absolute or relative toanchor 's package, of a file in the directory to scan.extensions- File-name suffixes to scan (e.g.".js" ). Must not be empty.- Throws:
IOException- If the directory cannot be located or a file cannot be read.org.opentest4j.AssertionFailedError- If no matching files were found, or any contains a closing script tag.
-
listResources
public static List<Path> listResources(Class<?> anchor, String resource, String... extensions) throws IOException Lists the files in the directory containing the specified resource that end with one of the specified suffixes.- Parameters:
anchor- Class used to resolveresource .resource- Resource path, absolute or relative toanchor 's package, of a file in the directory to scan.extensions- File-name suffixes to include.- Returns:
- The matching files, sorted by path. Never
null . - Throws:
IOException- If the resource does not exist, is not on the file system, or the directory cannot be listed.
-
findCloseTags
Finds each line of the specified text containing a closing script tag.- Parameters:
name- Name used to identify the text in the results (typically the file name).text- The text to scan.- Returns:
- A
name:line entry (1-based) for each offending line. Nevernull .
-