Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2015-01-12 11:46:38 +0000
committerMarkus Keller2015-01-12 11:46:38 +0000
commit83d48d8e25fcde38af87c234a9450953d1488b2a (patch)
tree688f6b580a62a9fcfa5679b45a61ba554a548ba3
parenta95f8a2791903995880f9847e2817d595f8e4538 (diff)
downloadeclipse.platform.text-83d48d8e25fcde38af87c234a9450953d1488b2a.tar.gz
eclipse.platform.text-83d48d8e25fcde38af87c234a9450953d1488b2a.tar.xz
eclipse.platform.text-83d48d8e25fcde38af87c234a9450953d1488b2a.zip
Bug 457230: HTML2TextReader mangles bold style ranges after <pre>I20150113-0800
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java57
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java17
2 files changed, 57 insertions, 17 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java
index 1d85c8b3275..b38a7fb85d7 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,6 +24,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.jface.internal.text.html.HTML2TextReader;
@@ -45,6 +46,13 @@ public class HTML2TextReaderTest extends TestCase {
return new TestSuite(HTML2TextReaderTest.class);
}
+ /**
+ * @param input
+ * @param expectedOutput
+ * @param styleRangeCount
+ * @throws IOException
+ * @deprecated pass actual style ranges
+ */
private void verify(String input, String expectedOutput, int styleRangeCount) throws IOException {
Reader reader= new StringReader(input);
TextPresentation textPresentation= new TextPresentation();
@@ -81,6 +89,42 @@ public class HTML2TextReaderTest extends TestCase {
}
+ private void verify(String input, String expectedOutput, StyleRange[] styleRanges) throws IOException {
+ Reader reader= new StringReader(input);
+ TextPresentation textPresentation= new TextPresentation();
+ HTML2TextReader htmlReader= new HTML2TextReader(reader, textPresentation);
+ String result= htmlReader.getString();
+ if (DEBUG)
+ System.out.println("<" + result + "/>");
+ assertEquals(expectedOutput, result);
+
+ Iterator styleRangeIterator= textPresentation.getAllStyleRangeIterator();
+ List ranges= new ArrayList();
+ while (styleRangeIterator.hasNext()) {
+ ranges.add(styleRangeIterator.next());
+ }
+
+ Collections.sort(ranges, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ StyleRange range1= (StyleRange)o1;
+ StyleRange range2= (StyleRange)o2;
+ return range1.start - range2.start;
+ }
+ });
+
+ assertEquals(Arrays.asList(styleRanges), ranges);
+
+ for (int i= 0; i < ranges.size() - 1; i++) {
+ StyleRange range1= (StyleRange)ranges.get(i);
+ StyleRange range2= (StyleRange)ranges.get(i + 1);
+
+ if (range1.start + range1.length > range2.start) {
+ assertTrue("StyleRanges overlap", false);
+ }
+ }
+
+ }
+
public void test0() throws IOException{
String string= "<code>3<5<code>";
String expected= "3<5";
@@ -211,5 +255,16 @@ public class HTML2TextReaderTest extends TestCase {
String expected= "This is yet another test";
verify(string, expected, 3);
}
+
+ public void testStylesWithPre() throws IOException {
+ String string= "I am <b>bold</b>.\n<p>\n<pre>One\n\n<b>T</b>hree.</pre>\n<p>\n<b>Author:</b> me.";
+ String expected= "I am bold. \nOne\n\nThree. \nAuthor: me.";
+ StyleRange[] ranges= {
+ new StyleRange(5, 4, null, null, SWT.BOLD),
+ new StyleRange(17, 1, null, null, SWT.BOLD),
+ new StyleRange(25, 7, null, null, SWT.BOLD)
+ };
+ verify(string, expected, ranges);
+ }
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java
index 24fd61672f2..a4f4ec15cce 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -75,7 +75,6 @@ public class HTML2TextReader extends SubstitutionTextReader {
private int fStrikeout= 0;
private int fStrikeoutStartOffset= -1;
private boolean fInParagraph= false;
- private boolean fIsPreformattedText= false;
private boolean fIgnore= false;
private boolean fHeaderDetected= false;
@@ -167,12 +166,10 @@ public class HTML2TextReader extends SubstitutionTextReader {
}
protected void startPreformattedText() {
- fIsPreformattedText= true;
setSkipWhitespace(false);
}
protected void stopPreformattedText() {
- fIsPreformattedText= false;
setSkipWhitespace(true);
}
@@ -188,8 +185,6 @@ public class HTML2TextReader extends SubstitutionTextReader {
return EMPTY_STRING;
else if (c == '&')
return processEntity();
- else if (fIsPreformattedText)
- return processPreformattedText(c);
return null;
}
@@ -219,9 +214,6 @@ public class HTML2TextReader extends SubstitutionTextReader {
return EMPTY_STRING;
}
- if (fIsPreformattedText)
- return EMPTY_STRING;
-
if ("b".equals(html)) { //$NON-NLS-1$
startBold();
return EMPTY_STRING;
@@ -343,13 +335,6 @@ public class HTML2TextReader extends SubstitutionTextReader {
return tagLen >= 5 && "--".equals(buf.substring(tagLen - 2)); //$NON-NLS-1$
}
- private String processPreformattedText(int c) {
- if (c == '\r' || c == '\n')
- fCounter++;
- return null;
- }
-
-
private void unread(int ch) throws IOException {
((PushbackReader) getReader()).unread(ch);
}

Back to the top