From 696e19da607c2381c516f0c750af2379023258af Mon Sep 17 00:00:00 2001 From: ozh Date: Fri, 15 May 2015 15:15:08 +0200 Subject: [PATCH] Better version string sanitizing --- includes/functions-formatting.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/functions-formatting.php b/includes/functions-formatting.php index 066f705..5e1206a 100644 --- a/includes/functions-formatting.php +++ b/includes/functions-formatting.php @@ -223,11 +223,15 @@ function yourls_trim_long_string( $string, $length = 60, $append = '[...]' ) { } /** - * Sanitize a version number (1.4.1-whatever -> 1.4.1) + * Sanitize a version number (1.4.1-whatever-RC1 -> 1.4.1) * + * @since 1.4.1 + * @param string $ver Version number + * @return string Sanitized version number */ function yourls_sanitize_version( $ver ) { - return preg_replace( '/[^0-9.]/', '', $ver ); + preg_match( '/(^[0-9.]+).*$/', $ver, $matches ); + return isset( $matches[1] ) ? trim( $matches[1], '.' ) : ''; } /** -- 2.45.0