-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle uri's according to the spec ps-id: 5491F726-E719-4A48-ABEA-477B5ADD8121
- Loading branch information
Showing
10 changed files
with
503 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
type t = | ||
{ scheme : string option | ||
{ scheme : string | ||
; authority : string | ||
; path : string | ||
} | ||
|
||
val of_string : string -> t | ||
|
||
val escape_path : string -> string | ||
val of_path : string -> t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
{ | ||
type t = | ||
{ scheme : string option | ||
{ scheme : string | ||
; authority : string | ||
; path : string | ||
} | ||
} | ||
|
||
rule path = parse | ||
| '/'? { path1 (Buffer.create 12) lexbuf } | ||
and path1 buf = parse | ||
| '\\' { Buffer.add_char buf '/' ; path1 buf lexbuf } | ||
| "%5" ['c' 'C'] { Buffer.add_char buf '/' ; path1 buf lexbuf } | ||
| "%3" ['a' 'A'] { Buffer.add_char buf ':' ; path1 buf lexbuf } | ||
| "%3" ['d' 'D'] { Buffer.add_char buf '=' ; path1 buf lexbuf } | ||
| "%3" ['f' 'F'] { Buffer.add_char buf '?' ; path1 buf lexbuf } | ||
| "%20" { Buffer.add_char buf ' ' ; path1 buf lexbuf } | ||
| _ as c { Buffer.add_char buf c ; path1 buf lexbuf } | ||
| eof { Buffer.contents buf } | ||
rule uri = parse | ||
([^':''/''?''#']+ as scheme ':') ? | ||
("//" ([^'/''?''#']* as authority)) ? | ||
([^'?''#']* as path) | ||
{ | ||
let open Import in | ||
let scheme = scheme |> Option.value ~default:"file" in | ||
let authority = | ||
authority |> Option.map Uri.pct_decode |> Option.value ~default:"" | ||
in | ||
let path = | ||
let path = path |> Uri.pct_decode in | ||
match scheme with | ||
| "http" | "https" | "file" -> | ||
String.add_prefix_if_not_exists path ~prefix:"/" | ||
| _ -> path | ||
in | ||
{ scheme; authority; path; } | ||
} | ||
|
||
and uri = parse | ||
| ([^ ':']+) as scheme ':' { uri1 (Some scheme) lexbuf } | ||
| "" { uri1 None lexbuf } | ||
and uri1 scheme = parse | ||
| "//" ([^ '/']* as authority) { uri2 scheme authority lexbuf } | ||
| "" { uri2 scheme "" lexbuf } | ||
and uri2 scheme authority = parse | ||
| "" { { scheme ; authority ; path = path lexbuf } } | ||
and path = parse | ||
| "" { { scheme = "file"; authority = ""; path = "/" } } | ||
| "//" ([^ '/']* as authority) (['/']_* as path) { { scheme = "file"; authority; path } } | ||
| "//" ([^ '/']* as authority) { { scheme = "file"; authority; path = "/" } } | ||
| ("/" _* as path) { { scheme = "file"; authority = ""; path } } | ||
| (_* as path) { { scheme = "file"; authority = ""; path = "/" ^ path } } | ||
|
||
{ | ||
let escape_path s = | ||
let lexbuf = Lexing.from_string s in | ||
path lexbuf | ||
|
||
{ | ||
let of_string s = | ||
let lexbuf = Lexing.from_string s in | ||
uri lexbuf | ||
|
||
let of_path s = | ||
let lexbuf = Lexing.from_string s in | ||
path lexbuf | ||
} |
Oops, something went wrong.