From 151201ad24f5bd64f2f15e65e0facd366d838769 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 13 Dec 2012 01:53:13 +0100 Subject: [PATCH] Fix string to number conversion Change-Id: Ib261bc61a5fd6ed99292a5021b173330b2fd96e7 Reviewed-by: Simon Hausmann --- qmljs_runtime.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index 1768cbf..21aa1c2 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -434,7 +434,8 @@ int __qmljs_string_length(ExecutionContext *, String *string) double __qmljs_string_to_number(ExecutionContext *, String *string) { - const QString s = string->toQString(); + QString s = string->toQString(); + s = s.trimmed(); if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X"))) return s.toLong(0, 16); bool ok; @@ -443,8 +444,10 @@ double __qmljs_string_to_number(ExecutionContext *, String *string) const char *end = 0; double d = qstrtod(begin, &end, &ok); if (end - begin != ba.size()) { - if (ba == "Infinity") + if (ba == "Infinity" || ba == "+Infinity") d = INFINITY; + else if (ba == "-Infinity") + d = -INFINITY; else d = nan(""); } -- 2.7.4