compiler
compiler copied to clipboard
Parse error from string escapes in `elm.json`
Quick Summary: The \/
JSON string escape is not parsed correctly in elm.json
files.
SSCCE
In elm.json
:
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm\/core": "1.0.5",
"elm\/json": "1.1.3"
},
"indirect": {
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
In src/Main.elm
(though it doesn't really matter):
module Main exposing (..)
main : Program () () ()
main = Platform.worker
{ init = \_ -> ( (), Cmd.none )
, update = \_ -> \_ -> ( (), Cmd.none )
, subscriptions = \_ -> Sub.none }
Output of elm make src/Main.elm
:
Dependencies ready!
-- PROBLEM WITH DEPENDENCY NAME --------------------------------------- elm.json
I got stuck while reading your elm.json file. There is something wrong with this
dependency name:
9| "elm\/core": "1.0.5",
^
Package names always include the name of the author, so I am expecting to see
dependencies like "mdgriffith/elm-ui" and "Microsoft/elm-json-tree-view".
I generally recommend finding the package you want on the package website, and
installing it with the elm install command!
Changing:
-
"elm\/core"
->"elm/core"
-
"elm\/json"
->"elm/json"
produces instead:
Dependencies ready!
Success! Compiled 1 module.
Main ───> index.html
- Elm: 0.19.1
- Browser: n/a
- Operating System: Tested on Debian Bullseye, Kubuntu 21.10, and Guix
Additional Details
According to RFC 7159 §7, the syntax for JSON strings is:
string = quotation-mark *char quotation-mark
char = unescaped /
escape (
%x22 / ; " quotation mark U+0022
%x5C / ; \ reverse solidus U+005C
%x2F / ; / solidus U+002F
%x62 / ; b backspace U+0008
%x66 / ; f form feed U+000C
%x6E / ; n line feed U+000A
%x72 / ; r carriage return U+000D
%x74 / ; t tab U+0009
%x75 4HEXDIG ) ; uXXXX U+XXXX
escape = %x5C ; \
quotation-mark = %x22 ; "
unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
so the concrete syntax "\/"
should parse the same as "/"
.
I encountered this issue while experimenting with improvements to the support for Elm in Guix (a "purely functional" package manager à la Nix). The (guix build json)
library chooses to always escape /
using the \/
sequence (even though it is superfluous).
Thanks for reporting this! To set expectations:
- Issues are reviewed in batches, so it can take some time to get a response.
- Ask questions in a community forum. You will get an answer quicker that way!
- If you experience something similar, open a new issue. We like duplicates.
Finally, please be patient with the core team. They are trying their best with limited resources.