From 5388951acbaadd684fcdc17c72e36af65eaba58d Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Sat, 18 Jan 2014 12:04:44 +0400 Subject: [PATCH] =?UTF-8?q?fonctions=20de=20v=C3=A9rification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ulib/semver | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ulib/semver b/ulib/semver index 2283901..f9ff484 100644 --- a/ulib/semver +++ b/ulib/semver @@ -5,6 +5,10 @@ uprovide semver urequire base +function __semver_check_version() { [ -z "${1//[a-zA-Z0-9.+-]/}" ]; } +function __semver_check_prelease() { [ -z "${1//[a-zA-Z0-9.-]/}" ]; } +function __semver_check_metadata() { [ -z "${1//[a-zA-Z0-9.-]/}" ]; } + function semver_parse() { local _ver="$1" _ma="${2:-major}" _mi="${3:-minor}" _pl="${4:-patchlevel}" _pr="${5:-prelease}" _md="${6:-metadata}" _va="${7:-valid}" local _tmp @@ -16,7 +20,7 @@ function semver_parse() { set_var "$_va" "" # vérifier les caractères valides - [ -z "${_ver//[a-zA-Z0-9.+-]/}" ] || return 1 + __semver_check_version "$_ver" || return 1 # extraire major _tmp= @@ -57,15 +61,16 @@ function semver_parse() { _tmp="$_ver" _ver= fi + __semver_check_prelease "$_tmp" || return 1 array_split "$_pr" "$_tmp" . fi # extraire metadata if [ "${_ver:0:1}" == + ]; then _ver="${_ver:1}" - [[ "$_ver" == *+* ]] && return 1 _tmp="$_ver" _ver= + __semver_check_metadata "$_tmp" || return 1 array_split "$_md" "$_tmp" . fi