Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Parsing is extremely fragile? #51

Closed
adamdahan opened this issue May 17, 2016 · 2 comments
Closed

Parsing is extremely fragile? #51

adamdahan opened this issue May 17, 2016 · 2 comments
Milestone

Comments

@adamdahan
Copy link

I have a little snippet for you to test and I am curious to know if you have any insights about why the parsing breaks down so easily before I go in and try to fix it up.

This markdown below should render a simple while loop

        ``\nwhile (YES) {\n    printf(\"Help, I am stuck in an infinite loop!\\n\");\n}\n``

But it does not render using your parser. Interestingly enough though this does:

       `` while (YES) { \n printf(\"Help, I am stuck in an infinite loop! \\n\"); } ``

I found that the initial newline and the last two newline chars are breaking it.

Any ideas?

@Coeur
Copy link
Collaborator

Coeur commented May 18, 2016

Hello @adamdahan, and thanks for raising the issue.

I built the regex myself in an attempt to be compatible with Character Escaping. See #46 for what was the problem, and 437d9a9#diff-842045870396c3236b1fad63acfe6264R140 for the solution (@"(?<!\\\\)(?:\\\\\\\\)*+(+)(.*?[^].*?)(\\1)(?!)"`).

In branch 3.x, the regex is the same, but written @"(?<!\\\\)(?:\\\\\\\\)*+" concatenated with @"(%@+)(.*?[^%@].*?)(\\1)(?!%@)" where %@ is replaced with ```.

I'll look into the issue, but feel free to provide a pull request to master.

@Coeur
Copy link
Collaborator

Coeur commented May 18, 2016

Maybe changing options:(NSRegularExpressionOptions)0 to options:NSRegularExpressionDotMatchesLineSeparators is enough.

@Coeur Coeur added this to the 2.1.1 milestone May 18, 2016
Coeur added a commit to Coeur/TSMarkdownParser that referenced this issue Jun 4, 2016
@Coeur Coeur closed this as completed Jun 4, 2016
Coeur added a commit that referenced this issue Jun 4, 2016
* master:
  italicSystem doesn't exist on OSX
  Fixed Multiline CodeEscaping [#51]
  fix broken compatibility with tvOS #52
  Fix OS X framework target

# Conflicts:
#	CHANGELOG.md
#	TSMarkdownParser.podspec
#	TSMarkdownParser.xcodeproj/project.pbxproj
#	TSMarkdownParser/TSMarkdownParser.m
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants