Skip to content

Commit

Permalink
a little better about stripping non-numeric prefixes containing .
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Mar 19, 2018
1 parent 1adabcd commit 50480e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/VersionParsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ splitparts(s::AbstractString) = map(digits2num, filter!(!isempty, split(s, '.'))

function vparse(s_::String)
s = replace(s_, ','=>".") # treat , as . (e.g MS resource-file syntax)
s = replace(s, r"^[^0-9.]+"=>"") # strip non-numeric prefix
s = replace(s, r"^[^\d]*[^.\d](\.?\d)"=>s"\1") # strip non-numeric prefix
isempty(s) && throw(ArgumentError("non-numeric version string $s_"))
contains(s, r"^\.\d") && (s = "0" * s) # treat .x as 0.x
if contains(s, r"^\d:\d+") # debian-style version number
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ using Compat.Test
@test vparse("2.1.0...+3") == v"2.1.0+3"

@test vparse("3,1,2") == v"3.1.2" == vparse("version 3.1.2, a good version")

@test vparse("A darn good version. 1.2") == v"1.2.0"
@test vparse("A darn good version. .2") == v"0.2.0"
@test_throws ArgumentError vparse("..2")

0 comments on commit 50480e9

Please sign in to comment.