r547 - in trunk/jrst/src: main/java/org/nuiton/jrst test/java/org/nuiton/jrst/bugs test/resources/bugs
Author: echatellier Date: 2011-03-04 10:40:37 +0100 (Fri, 04 Mar 2011) New Revision: 547 Url: http://nuiton.org/repositories/revision/jrst/547 Log: Fix #1378 : Tab causes nullPointerException (patch provided by Arnaud LIAGRE) Added: trunk/jrst/src/test/resources/bugs/testTab1378.rst Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2011-03-01 16:19:20 UTC (rev 546) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2011-03-04 09:40:37 UTC (rev 547) @@ -541,7 +541,7 @@ InputStream stream = url.openStream(); source = new InputSource(stream); } - + return source; } }); @@ -552,11 +552,9 @@ e.printStackTrace(); return null; } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (SAXException e) { - // TODO Auto-generated catch block e.printStackTrace(); return null; } Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-03-01 16:19:20 UTC (rev 546) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-03-04 09:40:37 UTC (rev 547) @@ -25,6 +25,8 @@ package org.nuiton.jrst; +import static org.nuiton.jrst.ReStructuredText.BLOCK_QUOTE; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.dom4j.DocumentHelper; @@ -135,8 +137,6 @@ public static final String LINE = "line"; - public static final String BLOCK_QUOTE = "block_quote"; - public static final String ATTRIBUTION = "attribution"; public static final String DOCTEST_BLOCK = "doctest_block"; @@ -943,12 +943,14 @@ Element result = null; String line = in.readLine(); if (line != null) { - if (line.matches("\\s*")) { + if (line.matches("\\s.*")) { + String savedLine = line; line = in.readLine(); + if (line != null) { int level = level(line); String blockQuote = null; - if (!(level == 0)) { + if (level != 0) { String txt = line; String[] lines = in.readWhile("(^ {" + level + "}.*)|(\\s*)"); @@ -966,7 +968,7 @@ if (blockQuote != null) { result.addAttribute(ATTRIBUTION, blockQuote); } - result.setText(txt); + result.setText(savedLine + txt); } } } @@ -2360,7 +2362,8 @@ */ private int level(String line) { int result = 0; - while (line.length() > result && line.charAt(result) == ' ') { + String sTmp = line.replaceAll("\\s", " "); + while (sTmp.length() > result && sTmp.charAt(result) == ' ') { result++; } return result; Modified: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java 2011-03-01 16:19:20 UTC (rev 546) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java 2011-03-04 09:40:37 UTC (rev 547) @@ -26,6 +26,8 @@ package org.nuiton.jrst.bugs; import java.io.File; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import junit.framework.Assert; @@ -52,14 +54,32 @@ @Test public void testLinksParameters() throws Exception { File in = new File("src/test/resources/bugs/testLinks.rst"); - File out = File.createTempFile("jrst-RstToHtml2", ".html"); + File out = File.createTempFile("jrst-testLinks", ".html"); out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); - System.out.println(content); Assert.assertTrue(content.indexOf("href=\"http://labs.libre-entreprise.org/tracker/?atid=113&group_id=8&func=browse\"") > 0); Assert.assertTrue(content.indexOf("href=\"http://www.docbook.org/\"") > 0); Assert.assertTrue(content.indexOf("href=\"http://www.docbook2.org/\"") > 0); } + + /** + * Test que la presence de caractere "tabulation" ne cause + * pas d'exception lors de la generation. + * + * @throws Exception + */ + @Test + public void testTabCharacter() throws Exception { + File in = new File("src/test/resources/bugs/testTab1378.rst"); + File out = File.createTempFile("jrst-testTab1378", ".html"); + out.deleteOnExit(); + JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + + String content = FileUtils.readFileToString(out); + Pattern pattern = Pattern.compile(".*<blockquote>.*du bla bla \u00E9l\u00E9mentaire.*</blockquote>.*", Pattern.DOTALL); + Matcher matcher = pattern.matcher(content); + Assert.assertTrue(matcher.find()); + } } Added: trunk/jrst/src/test/resources/bugs/testTab1378.rst =================================================================== --- trunk/jrst/src/test/resources/bugs/testTab1378.rst (rev 0) +++ trunk/jrst/src/test/resources/bugs/testTab1378.rst 2011-03-04 09:40:37 UTC (rev 547) @@ -0,0 +1,21 @@ +=================== +titre élémentaire 1 +=================== + +Sous-titre élémentaire 2 +------------------------ + + du bla bla élémentaire + +The easiest way to start is to use RESThub archetypes to create your first RESThub based application. Just open a command line terminal, and type : + +.. code-block:: bash + + mvn org.apache.maven.plugins:maven-archetype-plugin:2.0:generate -DarchetypeCatalog=http://resthub.org/nexus/content/repositories/releases/ + +You will have to choose between 3 RESThub archetypes : + + * **resthub-js-webapp-archetype** : simple HTML5/Javascript web application + * **resthub-tapestry5-webapp-archetype** : simple RESThub based Tapestry 5 web application + * **resthub-middle-archetype** : a JAR module for inclusion in your multi modules project + \ No newline at end of file
participants (1)
-
echatellier@users.nuiton.org