commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominik Stadler (JIRA)" <j...@apache.org>
Subject [jira] [Created] (EMAIL-127) ImageHtmlEmail: Dollar or Backslash in certain places in <img ... src...>-tags causes exceptions "IllegalArgumentException: Illegal group reference"
Date Thu, 27 Jun 2013 20:39:19 GMT
Dominik Stadler created EMAIL-127:
-------------------------------------

             Summary: ImageHtmlEmail: Dollar or Backslash in certain places in <img ...
src...>-tags causes exceptions "IllegalArgumentException: Illegal group reference"
                 Key: EMAIL-127
                 URL: https://issues.apache.org/jira/browse/EMAIL-127
             Project: Commons Email
          Issue Type: Bug
    Affects Versions: 1.3.1
         Environment: Linux
            Reporter: Dominik Stadler
            Priority: Blocker


I have a unit test which shows that dollar sign and backslash cause ImageHtmlEmail to throw
an Exception (unfortunately not easy to provide a complete unit test, but it should be easy
to enhance one of the existing tests for ImageHtmlEmail):

{quote}
			FileUtils.writeStringToFile(file, "<html>teststring <img title=\"$\" src=\"file://"
+ file.getAbsolutePath() + "\"/></html>");

			sender.sendHTMLEmail(files, mailConfig, emailConfig, REPORT_DIR);
{quote}

It will throw the following Exception:

{quote}
java.lang.IllegalArgumentException: Illegal group reference
	at java.util.regex.Matcher.appendReplacement(Matcher.java:808)
	at org.apache.commons.mail.ImageHtmlEmail.replacePattern(ImageHtmlEmail.java:180)
	at org.apache.commons.mail.ImageHtmlEmail.buildMimeMessage(ImageHtmlEmail.java:103)
	at org.apache.commons.mail.Email.send(Email.java:1427)
	at EmailSender.sendHTMLEmail(EmailSender.java:93)
	at EmailSenderTest.testImageHtmlEmailDollarBackslash(EmailSenderTest.java:801)
{quote}

the cause is that Matcher.appendReplacement() actually treats Dollar and Backslash as special
characters. From the javadoc of Matcher:

{quote}
     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>)
in
     * the replacement string may cause the results to be different than if it
     * were being treated as a literal replacement string. Dollar signs may be
     * treated as references to captured subsequences as described above, and
     * backslashes are used to escape literal characters in the replacement
     * string.
{quote}

A possible fix is to replace line 180 of ImageHtmlEmail.java with the following, i.e. replace
"$" by "\$" and "\" by "\\" to have them properly escaped.

{code}
matcher.appendReplacement(stringBuffer, (matcher.group(1) + "cid:" + cid + matcher.group(3)).replace("$",
"\\$").replace("\\", "\\\\"));
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message