allcolor / YaHP-Converter

YaHP is a Java library that allows you to convert an HTML document into a PDF document.
GNU Lesser General Public License v2.1
56 stars 23 forks source link

Bug on <script> parsing in CHtmlToPdfFlyingSaucerTransformer.java 1.3 #2

Closed sankarom closed 10 years ago

sankarom commented 12 years ago

Hi, There is a bug in the " while for" instruction code line 136 : some scripts are forgotten by the algorithm.

REPLACE :

final List toRemove = new ArrayList(); final Pattern p = Pattern.compile("(<script\s*)"); final Matcher m = p.matcher(a); int start = 0; while (m.find(start)) { final int is = m.start(); int ie = m.start(); while (ie < a.length()) { if (a.substring(ie).startsWith("")) { ie = ie + 9; break; } else { ie++; } } start = ie + 1; toRemove.add(a.substring(is, ie)); if (start >= a.length()) { break; } } for (int i = 0; i < toRemove.size(); i++) { final String rem = (String) toRemove.get(i); final int index = a.indexOf(rem); a = a.substring(0, index) + a.substring(index + rem.length()); }

BY:

    Pattern script = Pattern.compile("<script.*?>.*?</script>");
    Matcher mscript = script.matcher(a);
    while (mscript.find()) a = mscript.replaceAll("");