@@ -18,12 +18,16 @@ defmodule Version do
1818
1919 MAJOR.MINOR.PATCH
2020
21+ Each numeric component is limited to at most 14 digits.
22+
2123 Pre-releases are supported by optionally appending a hyphen and a series of
2224 period-separated identifiers immediately following the patch version.
2325 Identifiers consist of only ASCII alphanumeric characters and hyphens (`[0-9A-Za-z-]`):
2426
2527 "1.0.0-alpha.3"
2628
29+ Numeric pre-release identifiers are also limited to at most 14 digits.
30+
2731 Build information can be added by appending a plus sign and a series of
2832 dot-separated identifiers immediately following the patch or pre-release version.
2933 Identifiers consist of only ASCII alphanumeric characters and hyphens (`[0-9A-Za-z-]`):
@@ -520,6 +524,8 @@ defmodule Version do
520524 defmodule Parser do
521525 @ moduledoc false
522526
527+ @ max_numeric_component_digits 14
528+
523529 operators = [
524530 { ">=" , :>= } ,
525531 { "<=" , :<= } ,
@@ -621,7 +627,9 @@ defmodule Version do
621627 defp require_digits ( nil ) , do: :error
622628
623629 defp require_digits ( string ) do
624- if leading_zero? ( string ) , do: :error , else: parse_digits ( string , "" )
630+ if leading_zero? ( string ) or byte_size ( string ) > @ max_numeric_component_digits ,
631+ do: :error ,
632+ else: parse_digits ( string , "" )
625633 end
626634
627635 defp leading_zero? ( << ?0 , _ , _ :: binary >> ) , do: true
@@ -649,6 +657,11 @@ defmodule Version do
649657 end
650658 end
651659
660+ defp convert_parts_to_integer ( [ part | rest ] , acc )
661+ when byte_size ( part ) > @ max_numeric_component_digits do
662+ if all_digits? ( part ) , do: :error , else: convert_parts_to_integer ( rest , [ part | acc ] )
663+ end
664+
652665 defp convert_parts_to_integer ( [ part | rest ] , acc ) do
653666 case parse_digits ( part , "" ) do
654667 { :ok , integer } ->
@@ -667,6 +680,10 @@ defmodule Version do
667680 { :ok , Enum . reverse ( acc ) }
668681 end
669682
683+ defp all_digits? ( << char , rest :: binary >> ) when char in ?0 .. ?9 , do: all_digits? ( rest )
684+ defp all_digits? ( << >> ) , do: true
685+ defp all_digits? ( _other ) , do: false
686+
670687 defp valid_identifier? ( << char , rest :: binary >> )
671688 when char in ?0 .. ?9
672689 when char in ?a .. ?z
0 commit comments