jgm / jgm/commonmark-hs

`show :: SourceRange -> String` is ambiguous

Open
#91 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
145
Forks
38
PR merge metrics
No merged PRs in 30d

Description

For admittedly uncommon filenames & degenerate ranges there is ambiguity in the implementation of `show :: SourceRange -> String`. Consider the following two examples:
```
λ> import Text.Parsec.Pos
λ> show $ SourceRange [(newPos "asdf" 0 0, newPos "asdf" 0 0), (newPos "asdf" 0 0, newPos "" 0 0)]
"asdf@0:0-0:0;0:0-@0:0"
λ> show $ SourceRange [(newPos "asdf" 0 0, newPos "0:0;0:0-" 0 0)]
"asdf@0:0-0:0;0:0-@0:0"
```

I discovered this while writing a parser for such ranges. This is probably sufficiently degenerate that it doesn't necessarily need to be fixed, but it should be possible to escape the filename without complicating the implementation or impacting performance too much.

I would suggest simply enforcing that filenames containing `:` or `-` are printed escaped as `show` normally does. That is the second range here would instead be shown as the string: `"asdf@0:0-\"0:0;0:0-\"@0:0"`. The first case would remain unchanged.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.