diff --git a/commons-email2-jakarta/pom.xml b/commons-email2-jakarta/pom.xml index 7358e941b..f3dfdc66d 100644 --- a/commons-email2-jakarta/pom.xml +++ b/commons-email2-jakarta/pom.xml @@ -78,6 +78,18 @@ mockito-core test + + org.openjdk.jmh + jmh-core + ${jmh.version} + test + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + test + @@ -92,6 +104,7 @@ 0.18 0.84 0.76 + 1.37 diff --git a/commons-email2-jakarta/src/main/java/org/apache/commons/mail2/jakarta/ImageHtmlEmail.java b/commons-email2-jakarta/src/main/java/org/apache/commons/mail2/jakarta/ImageHtmlEmail.java index 615c0a479..6ef37c5bf 100644 --- a/commons-email2-jakarta/src/main/java/org/apache/commons/mail2/jakarta/ImageHtmlEmail.java +++ b/commons-email2-jakarta/src/main/java/org/apache/commons/mail2/jakarta/ImageHtmlEmail.java @@ -29,8 +29,9 @@ /** *

- * Small wrapper class on top of HtmlEmail which encapsulates the required logic to retrieve images that are contained in "<img src=../>" elements in the - * HTML code. This is done by replacing all img-src-elements with "cid:"-entries and embedding images in the email. + * Small wrapper class on top of HtmlEmail which encapsulates the required logic to retrieve images and scripts that are contained in + * "<img src=../>" and "<script src=../>" elements in the HTML code. + * This is done by replacing all the src-elements with "cid:"-entries and embedding the images/scripts in the email. *

*

* For local files the class tries to either load them via an absolute path or - if available - use a relative path starting from a base directory. For files @@ -49,10 +50,10 @@ public class ImageHtmlEmail extends HtmlEmail { // can be arbitrary text between "IMG" and "SRC" like IDs and other things. /** Regexp for extracting {@code } tags */ - public static final String REGEX_IMG_SRC = "(<[Ii][Mm][Gg]\\s*[^>]*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])"; + public static final String REGEX_IMG_SRC = "(<[Ii][Mm][Gg](?=\\s)[^>]*?\\s[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+)([\"'])"; /** Regexp for extracting {@code ", Arrays.asList("s")), + Arguments.of("", Arrays.asList("s")), + // uppercase + Arguments.of("", Arrays.asList("s")), + // matches twice + Arguments.of("", Arrays.asList("s1", "s2")), + // what about newlines + Arguments.of("", Arrays.asList("s1", "s2")), + // what about newlines and other whitespaces + Arguments.of("", Arrays.asList("s1", "s2")), + // what about some real markup + Arguments.of("", Arrays.asList("/jkao/_next/static/chunks/polyfills-c67a75d1b6f99dc8.js")), + // try with 5 + Arguments.of("", Arrays.asList("s1", "s2", "s3", "s4", "s5")), + // try with invalid scripts + Arguments.of("