From 65fc198f33f8efc5d1d5ade3985c35bfeeee0dfc Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Wed, 21 Aug 2024 18:39:32 +0200 Subject: [PATCH] #153 Ignore 'javascript:' URLs --- .../src/main/java/org/aim42/htmlsanitycheck/tools/Web.java | 4 ++++ .../groovy/org/aim42/htmlsanitycheck/tools/WebSpec.groovy | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/tools/Web.java b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/tools/Web.java index f8209d58..240524ed 100644 --- a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/tools/Web.java +++ b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/tools/Web.java @@ -158,6 +158,9 @@ public static boolean isRemoteURL(String imgSrc) { || startsWithIP(imgSrc); } + public static boolean isVirtualURL(String resource) { + return resource.startsWith("javascript:"); + } /** * Checks if this String represents a data-image-URI @@ -211,6 +214,7 @@ public static boolean isLocalResource(String link) { || (link.isEmpty()) || isCrossReference(link) // "#link" or similar || isRemoteURL(link) // "mailto:", "http" etc + || isVirtualURL(link) // "javascript:" ... ) { return false; } else { diff --git a/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/tools/WebSpec.groovy b/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/tools/WebSpec.groovy index 37d06be4..1ea9866e 100644 --- a/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/tools/WebSpec.groovy +++ b/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/tools/WebSpec.groovy @@ -107,6 +107,7 @@ class WebSpec extends Specification { false | "10.0.0.1/index.html" // this is a valid REMOTE address, defaults to http or https + false | "javascript:dummy" } @Unroll @@ -142,7 +143,5 @@ class WebSpec extends Specification { false | "1.2.3" false | "1.2" false | "110" - - } } \ No newline at end of file