#17 Bug in MarkupStripper.stripInternalLinks

open
nobody
None
5
2012-09-14
2012-09-14
Tim Allison
No

MarkupStripper stripper = new MarkupStripper();
String s = "range of disorders on the [[autism spectrum]] or to the various";
Character c = new Character(' ');
System.out.println(stripper.stripInternalLinks(s, c));

Yields:
range of disorders on the 64autism spectrum or to the various

Where did that 64 come from? Apparently, Java is casting the Character to an int for the first addition 32+32, then realizes that it is concatenating a string and then does the second replacement+replacement correctly.

The problem is this line:
strippedLinkMarkup = replacement+replacement + dest +replacement+replacement ;

One simple solution:
strippedLinkMarkup = ""+replacement+replacement + dest +replacement+replacement ;

Discussion

  • Tim Allison
    Tim Allison
    2012-09-14

    Also recommend changing this line:
    strippedLinkMarkup = replacement + replacement + dest.replaceAll(".", replacement.toString()) + replacement + anchor.substring(1) + anchor.substring(1) + replacement ;

    to:
    strippedLinkMarkup = replacement + replacement + dest.replaceAll(".", replacement.toString()) + replacement + anchor.substring(1) + replacement ;