Skip to content

Commit efd3edf

Browse files
committed
split_into_units: Don't break for SI prefixes only
Fixes #46
1 parent f125acc commit efd3edf

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/cldr/unit/parser.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ defmodule Cldr.Unit.Parser do
347347
end
348348

349349
for {prefix, _scale} <- Prefix.si_factors() do
350-
def split_into_units(<<unquote(prefix), rest::binary>>) do
350+
def split_into_units(<<unquote(prefix), rest::binary>>) when byte_size(rest) > 0 do
351351
[head | rest] = split_into_units(rest)
352352
[unquote(prefix) <> head | rest]
353353
end

test/cldr_units_test.exs

+5
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ defmodule Cldr.UnitsTest do
251251
{Cldr.Unit.UnitNotTranslatableError, "The unit \"milliliter\" is not translatable"}}
252252
end
253253

254+
test "validate unit does not break for SI prefixes only" do
255+
assert Cldr.Unit.validate_unit("milli") ==
256+
{:error, {Cldr.UnknownUnitError, "Unknown unit was detected at \"milli\""}}
257+
end
258+
254259
test "Unit of 1 retrieves a default pattern is plural category pattern does not exist" do
255260
unit = Cldr.Unit.new!(1, :pascal)
256261
assert Cldr.Unit.to_string(unit, locale: "de", style: :short) == {:ok, "1 Pa"}

0 commit comments

Comments
 (0)