Fix recognition of float and double literals of the form ".0" and "0."
This commit is contained in:
parent
386e2c1e29
commit
e04b960557
3 changed files with 21 additions and 0 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -5,6 +5,18 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
[Keep a CHANGELOG](http://keepachangelog.com).
|
||||
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixed
|
||||
|
||||
- strings of the form `".0"` and `"0."` weren't recognized as valid XSD float
|
||||
and double literals
|
||||
|
||||
|
||||
[Compare v0.9.2...HEAD](https://github.com/rdf-elixir/rdf-ex/compare/v0.9.2...HEAD)
|
||||
|
||||
|
||||
|
||||
## 0.9.2 - 2021-01-06
|
||||
|
||||
### Added
|
||||
|
|
|
@ -46,11 +46,17 @@ defmodule RDF.XSD.Double do
|
|||
end
|
||||
|
||||
@impl XSD.Datatype
|
||||
def lexical_mapping(lexical, opts)
|
||||
def lexical_mapping("." <> lexical, opts), do: lexical_mapping("0." <> lexical, opts)
|
||||
|
||||
def lexical_mapping(lexical, opts) do
|
||||
case Float.parse(lexical) do
|
||||
{float, ""} ->
|
||||
float
|
||||
|
||||
{float, "."} ->
|
||||
float
|
||||
|
||||
{float, remainder} ->
|
||||
# 1.E-8 is not a valid Elixir float literal and consequently not fully parsed with Float.parse
|
||||
if Regex.match?(~r/^\.e?[\+\-]?\d+$/i, remainder) do
|
||||
|
|
|
@ -141,6 +141,9 @@ defmodule RDF.XSD.TestData do
|
|||
"-1" => {-1.0e0, "-1", "-1.0E0"},
|
||||
"+01.000" => {1.0e0, "+01.000", "1.0E0"},
|
||||
"1.0" => {1.0e0, "1.0", "1.0E0"},
|
||||
"0." => {0.0e0, "0.", "0.0E0"},
|
||||
".0" => {0.0e0, ".0", "0.0E0"},
|
||||
".0E0" => {0.0e0, ".0E0", "0.0E0"},
|
||||
"123.456" => {1.23456e2, "123.456", "1.23456E2"},
|
||||
"1.0e+1" => {1.0e1, "1.0e+1", "1.0E1"},
|
||||
"1.0e-10" => {1.0e-10, "1.0e-10", "1.0E-10"},
|
||||
|
|
Loading…
Reference in a new issue