<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>Bug in parseData(String rawData) in ProcessingInstruction.java</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Dear all:</FONT>
</P>
<P> <FONT SIZE=2><?pi href = ”<A HREF="http://www.jdom.org" TARGET="_blank">http://www.jdom.org</A>” media = “wap”?> <!-- Please note the spaces inserted between the equal, ‘=’, signs.--></FONT></P>
<P><FONT SIZE=2>won’t be parsed properly if you set data via the following code snippet.</FONT>
<BR><FONT SIZE=2>ProcessingInstruction pi(“pi”, “href = \”<A HREF="http://www.jdom.org\" TARGET="_blank">http://www.jdom.org\</A>” media = \“wap\””); </FONT>
<BR><FONT SIZE=2>// Please note the spaces inserted between the equal, ‘=’, signs.</FONT>
</P>
<P> <FONT SIZE=2>After hacking into the source, org.jdom.ProcessingInstuction.java, it failed on the privte function:</FONT>
<BR><FONT SIZE=2>private Map paresData(String rawData), while parsing the media attribute.</FONT>
<BR> <FONT SIZE=2>The suspicious code is “pos += value.lenth() + 1;” in code sinppet below:</FONT>
<BR> <FONT SIZE=2>….</FONT>
<BR><FONT SIZE=2> if (currentChar == '=') {</FONT>
<BR><FONT SIZE=2> name = inputData.substring(startName, pos).trim();</FONT>
<BR><FONT SIZE=2> value = extractQuotedString(inputData.substring(pos+1).trim());</FONT>
<BR><FONT SIZE=2> // A null value means a parse error and we return empty!</FONT>
<BR><FONT SIZE=2> if (value == null) {</FONT>
<BR><FONT SIZE=2> return new HashMap();</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> pos += value.length() + 1; // skip over equals and value</FONT>
<BR><FONT SIZE=2> break;</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR> <FONT SIZE=2>……</FONT>
<BR><FONT SIZE=2>⇨ Since there are extra spaces between ‘=’ sign for the first “href” attribute, we shouldn’t just naiively use pos += value.length() + 1 to skip over value. This will not move to the media attribute, but rather between the value of href.</FONT></P>
<P><FONT SIZE=2>Regards,</FONT>
<BR><FONT SIZE=2>Albert</FONT>
</P>
<BR>
<BR>
<BR>
</BODY>
</HTML>