redpen-cc / redpen

RedPen is an open source proofreading tool to check if your technical documents meet the writing standard. RedPen supports various markup text formats (Markdown, Textile, AsciiDoc, Re:VIEW, reStructuredText and LaTeX).
https://redpen.cc
Apache License 2.0
567 stars 74 forks source link

Crash: link to reference is nested in image when format is JSON #816

Closed rhysd closed 6 years ago

rhysd commented 6 years ago

How to repro

[![foo](foo)][bar]

[bar]: bar

Save above doc as tmp.md and run redpen -r json tmp.md

Log

[2017-12-12 13:15:45.717][INFO ] cc.redpen.Main - Configuration file: /usr/local/Cellar/redpen/1.10.0/libexec/conf/redpen-conf-en.xml
[2017-12-12 13:15:45.723][INFO ] cc.redpen.config.ConfigurationLoader - Loading config from specified config file: "/usr/local/Cellar/redpen/1.10.0/libexec/conf/redpen-conf-en.xml"
[2017-12-12 13:15:45.734][INFO ] cc.redpen.config.ConfigurationLoader - Succeeded to load configuration file
[2017-12-12 13:15:45.734][INFO ] cc.redpen.config.ConfigurationLoader - Language is set to "en"
[2017-12-12 13:15:45.734][WARN ] cc.redpen.config.ConfigurationLoader - No variant configuration...
[2017-12-12 13:15:45.786][INFO ] cc.redpen.config.ConfigurationLoader - No "symbols" block found in the configuration
[2017-12-12 13:15:45.789][INFO ] cc.redpen.config.SymbolTable - Default symbol settings are loaded
[2017-12-12 13:15:45.792][INFO ] cc.redpen.parser.SentenceExtractor - "[., ?, !]" are added as a end of sentence characters
[2017-12-12 13:15:45.792][INFO ] cc.redpen.parser.SentenceExtractor - "[', "]" are added as a right quotation characters
[2017-12-12 13:15:46.101][WARN ] cc.redpen.parser.markdown.ToFileContentSerializer - Failed to add parent for a Section
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(ArrayList.java:418)
    at java.util.ArrayList.get(ArrayList.java:431)
    at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:412)
    at org.pegdown.ast.RefLinkNode.accept(RefLinkNode.java:33)
    at cc.redpen.parser.markdown.ToFileContentSerializer.visitChildren(ToFileContentSerializer.java:74)
    at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:452)
    at org.pegdown.ast.SuperNode.accept(SuperNode.java:43)
    at cc.redpen.parser.markdown.ToFileContentSerializer.visitChildren(ToFileContentSerializer.java:74)
    at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:300)
    at org.pegdown.ast.ParaNode.accept(ParaNode.java:35)
    at cc.redpen.parser.markdown.ToFileContentSerializer.visitChildren(ToFileContentSerializer.java:74)
    at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:315)
    at org.pegdown.ast.RootNode.accept(RootNode.java:51)
    at cc.redpen.parser.markdown.ToFileContentSerializer.toFileContent(ToFileContentSerializer.java:90)
    at cc.redpen.parser.MarkdownParser.parse(MarkdownParser.java:79)
    at cc.redpen.parser.BaseDocumentParser.parse(BaseDocumentParser.java:58)
    at cc.redpen.RedPen.parse(RedPen.java:131)
    at cc.redpen.Main.getDocuments(Main.java:221)
    at cc.redpen.Main.run(Main.java:196)
    at cc.redpen.Main.main(Main.java:60)

Environment

OS

macOS 10.12

redpen

v1.10.0 (installed via brew install)

Java

java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
takahi-i commented 6 years ago

Hello @rhysd. Thank you very much for the detailed report on the crash 🙏 I will fix this issue.

rhysd commented 6 years ago

I encountered this when writing a CI badge as following:

[![Mac and Linux Build Status][]][Travis CI]

<!-- snip... -->

[Mac and Linux Build Status]: https://travis-ci.org/rhysd/github-clone-all.svg?branch=master
[Travis CI]: https://travis-ci.org/rhysd/github-clone-all

And this does not occur with v1.9.0

takahi-i commented 6 years ago

I succeeded to reproduce the problem in my environments thanks to your report 🙏

➜  redpen git:(master) redpen -r json ~/tmp/foo.md
[2017-12-13 23:31:47.920][INFO ] cc.redpen.Main - Configuration file: /opt/brew/Cellar/redpen/1.10.0/libexec/conf/redpen-conf-en.xml
[2017-12-13 23:31:47.926][INFO ] cc.redpen.config.ConfigurationLoader - Loading config from specified config file: "/opt/brew/Cellar/redpen/1.10.0/libexec/conf/redpen-conf-en.xml"
[2017-12-13 23:31:47.945][INFO ] cc.redpen.config.ConfigurationLoader - Succeeded to load configuration file
[2017-12-13 23:31:47.945][INFO ] cc.redpen.config.ConfigurationLoader - Language is set to "en"
[2017-12-13 23:31:47.945][WARN ] cc.redpen.config.ConfigurationLoader - No variant configuration...
[2017-12-13 23:31:47.948][INFO ] cc.redpen.config.ConfigurationLoader - No "symbols" block found in the configuration
[2017-12-13 23:31:47.952][INFO ] cc.redpen.config.SymbolTable - Default symbol settings are loaded
[2017-12-13 23:31:47.959][INFO ] cc.redpen.parser.SentenceExtractor - "[., ?, !]" are added as a end of sentence characters
[2017-12-13 23:31:47.960][INFO ] cc.redpen.parser.SentenceExtractor - "[', "]" are added as a right quotation characters
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.parboiled.transform.AsmUtils (file:/opt/brew/Cellar/redpen/1.10.0/libexec/lib/parboiled-java-1.1.7.jar) to method java.lang.ClassLoader.findLoadedClass(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.parboiled.transform.AsmUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index -1 out-of-bounds for length 0
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
        at java.base/java.util.Objects.checkIndex(Objects.java:372)
        at java.base/java.util.ArrayList.get(ArrayList.java:440)
        at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:412)
        at org.pegdown.ast.RefLinkNode.accept(RefLinkNode.java:33)
        at cc.redpen.parser.markdown.ToFileContentSerializer.visitChildren(ToFileContentSerializer.java:74)
        at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:452)
        at org.pegdown.ast.SuperNode.accept(SuperNode.java:43)
        at cc.redpen.parser.markdown.ToFileContentSerializer.visitChildren(ToFileContentSerializer.java:74)
        at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:300)
        at org.pegdown.ast.ParaNode.accept(ParaNode.java:35)
        at cc.redpen.parser.markdown.ToFileContentSerializer.visitChildren(ToFileContentSerializer.java:74)
        at cc.redpen.parser.markdown.ToFileContentSerializer.visit(ToFileContentSerializer.java:315)
        at org.pegdown.ast.RootNode.accept(RootNode.java:51)
        at cc.redpen.parser.markdown.ToFileContentSerializer.toFileContent(ToFileContentSerializer.java:90)
        at cc.redpen.parser.MarkdownParser.parse(MarkdownParser.java:79)
        at cc.redpen.parser.BaseDocumentParser.parse(BaseDocumentParser.java:58)
        at cc.redpen.RedPen.parse(RedPen.java:131)
        at cc.redpen.Main.getDocuments(Main.java:221)
        at cc.redpen.Main.run(Main.java:196)
        at cc.redpen.Main.main(Main.java:60)
takahi-i commented 6 years ago

Very sorry for making you wait. I made the hot fix for this problem in #818 Hopefully this fix work for your environment.

takahi-i commented 6 years ago

Hello @rhysd, I fix this issue since I confirmed the hotfix in #818 works. Please reopen this issue or create another one when you face the same problem.

takahi-i commented 6 years ago

I will release the new version of RedPen containing this hotfix soon.

takahi-i commented 6 years ago

I made the release containing the hotfix https://github.com/redpen-cc/redpen/releases/tag/redpen-1.10.1. The release is also applied to Homebrew at pr https://github.com/Homebrew/homebrew-core/pull/21759.

rhysd commented 6 years ago

After upgrading redpen via Homebrew, it backs to work fine now. Thank you for your quick fix :+1: