Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix quoted URL path failures #39

Merged
merged 3 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ team.

## Status

We support [Dhall 15.0.0][dhall-15], including the `with` keyword and record puns.
We support [Dhall 15.0.0][dhall-15], including the `with` keyword and record puns. We do not support
[URLs with quoted paths](https://docs.dhall-lang.org/howtos/migrations/Deprecation-of-quoted-paths-in-URLs.html),
which were deprecated in 15.0.0 and will be removed in 17.0.0. We currently do support
`Optional/build` and `Optional/fold`, which will also be removed in 17.0.0.


We're running the [Dhall acceptance test suites][dhall-tests] for parsing, normalization,
[CBOR][cbor] encoding and decoding, hashing, and type inference (everything except imports), and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import org.dhallj.core.DhallException.ParsingFailure;
import org.dhallj.core.Expr;
import org.dhallj.core.Operator;
import org.dhallj.core.Source;
Expand Down Expand Up @@ -664,7 +665,7 @@ static final Expr.Parsed makeImport(
try {
value = Expr.makeRemoteImport(new URI(type.image), using, mode, hash);
} catch (java.net.URISyntaxException e) {
System.out.println(e);
throw new ParsingFailure("Invalid URL", e);
}
} else if (type.image.startsWith("env:")) {
value = Expr.makeEnvImport(type.image.substring(4), mode, hash);
Expand All @@ -674,7 +675,7 @@ static final Expr.Parsed makeImport(
try {
value = Expr.makeLocalImport(Paths.get(type.image), mode, hash);
} catch (java.nio.file.InvalidPathException e) {
System.out.println(e);
throw new ParsingFailure("Invalid path", e);
}
}

Expand Down
3 changes: 2 additions & 1 deletion modules/parser/src/main/javacc/JavaCCParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ TOKEN: {
| ["\u0030"-"\u003b"] | ["\u0040"-"\u005a"] | ["\u0040"-"\u005a"] | ["\u005e"-"\u007a"]>
| <#QUOTED_PATH_CHARACTER: ["\u0020"-"\u0021"] | ["\u0023"-"\u002e"] | ["\u0030"-"\u007f"] | <VALID_NON_ASCII>>
| <#PATH_COMPONENT: "/" ((<PATH_CHARACTER>)+ | ("\"" (<QUOTED_PATH_CHARACTER>)+ "\""))>
| <#URL_PATH_COMPONENT: "/" ((<PATH_CHARACTER>)+)>
| <#PATH: (<PATH_COMPONENT>)+>
| <#PARENT_PATH: ".." <PATH>>
| <#HERE_PATH: "." <PATH>>
| <#HOME_PATH: "~" <PATH>>
| <#URL_PATH: (<PATH_COMPONENT> | ("/") <SEGMENT>)*>
| <#URL_PATH: (<URL_PATH_COMPONENT> | ("/") <SEGMENT>)*>
}

<WITHIN_DOUBLE_QUOTE> TOKEN: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.net.URI
import java.nio.file.Paths

import munit.{FunSuite, Ignore}
import org.dhallj.core.DhallException.ParsingFailure
import org.dhallj.core.Expr
import org.dhallj.core.Expr.ImportMode

Expand Down Expand Up @@ -73,4 +74,8 @@ class DhallParserSuite extends FunSuite() {

assert(DhallParser.parse("classpath:/foo/bar.dhall as Text") == expected)
}

test("fail on URLs with quoted paths") {
intercept[ParsingFailure](DhallParser.parse("https://example.com/foo/\"bar?baz\"?qux"))
}
}