Scala/Java library for Internationalized Resource Identifier (IRIs) support
  • Scala 92.7%
  • Java 7.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Albert Pető b7b0edf010 Specify UTF8 charset when parsing percent encoded characters (#29)
* Ensure that percent-encoded UTF8 character are correctly interpreted

* Add test cases for parsing percent-encoded characters
2019-12-10 18:31:06 +01:00
akka-http/src Fix akka query encoding conversion (#23) 2019-11-08 10:13:03 +01:00
contextual/src Implement lazy parsing of iris (#8) 2019-10-10 08:57:53 +02:00
project Improved model (#5) 2019-10-06 11:46:55 +02:00
src Specify UTF8 charset when parsing percent encoded characters (#29) 2019-12-10 18:31:06 +01:00
.gitignore Initial commit 2019-02-02 10:40:56 +01:00
.scalafmt.conf Contextual iri (#4) 2019-09-13 13:23:27 +02:00
.travis.yml Contextual iri (#4) 2019-09-13 13:23:27 +02:00
build.sbt Update version to 0.2.7-SNAPSHOT 2019-12-10 18:25:30 +01:00
LICENSE Initial commit 2019-02-02 10:40:56 +01:00
README.md Release v0.2.6 2019-11-12 17:41:49 +01:00

capturl

Build Status Maven Central Software License

Capturl is a Scala/Java library that provide parsers and models to work with Internationalized Resource Identifier aka IRIs.

The implementation is strongly inspired by the great akka-http Uri model with modularity and simplicity in mind.

Versions

Version Release date Scala versions
0.2.6 2019-11-12 2.11.12 (excluded capturl-contextual), 2.12.10
0.2.5 2019-11-11 2.11.12 (excluded capturl-contextual), 2.12.10
0.2.4 2019-11-08 2.11.12 (excluded capturl-contextual), 2.12.10
0.2.3 2019-11-06 2.11.12 (excluded capturl-contextual), 2.12.10
0.2.2 2019-10-31 2.11.12 (excluded capturl-contextual), 2.12.10
0.2.1 2019-10-29 2.11.12 (excluded capturl-contextual), 2.12.10
0.2.0 2019-10-11 2.11.12 (excluded capturl-contextual), 2.12.10

Setup

Add to your build.sbt:

libraryDependencies += "fr.davit" %% "capturl" % <version>

Parsers

All the apply/create methods accepting String input will be validated against RFC 3987 compliant parsers to create the model classes.

Warning: Exception is made for spaces in path, query and fragment which are allowed at the moment (see TODOs)

If you are sure about your input, and want to skip validation for efficiency reason, you can construct the models using the implementation classes. eg:

Scheme("b@d_scheme") // throws a parsing exception
Scheme.Protocol("b@d_scheme") // this is very wrong but will create your scheme

Normalization

Those are the IRI normalization steps:

  • Scheme
    • lower case normalization
  • Hosts
    • NamedHost are lower cased and decoded (punycode)
    • IPv4 and IPv6 are normalized
  • Path
    • collapse current folder
    • collapse parent folder
  • Query
    • spaces are replaced by '+'
  • Iri
    • omit custom port if matches the scheme default port
    • root path is added for absolute / host relative iris
    • default port is hidden
  • General
    • all encoded characters are decoded

IRI string interpolation

Add to your build.sbt:

libraryDependencies += "fr.davit" %% "capturl-contextual" % <version>

This sub module provides compile time string interpolation to create IRIs:

val iri = iri"http://localhost:8080/path?key#identifier"

If iri string is not valid, the scala compiler will notify you:

val iri = iri"http://user{info@example.com/"
[error] Invalid IRI http://user{info@example.com/
[error]     iri"http://user{info@example.com/"
[error]         ^
[error] one error found

TODO

  • provide strict / relax parser mode
  • provide more normalization options
  • support holes in interpolation
  • support scala 2.13

capturl-akka-http

Add to your build.sbt:

libraryDependencies += "fr.davit" %% "capturl-akka-http" % <version>

This sub module provides all the necessary implicits in UriConverters to go from an Iri to the akka Uri model.

TODO

  • provide converters for akka-http javadsl model