[libgdata] Bug 584737 – String parsing is locale-sensitive
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgdata] Bug 584737 – String parsing is locale-sensitive
- Date: Thu, 4 Jun 2009 06:37:52 -0400 (EDT)
commit 1b2292336c6864456ad84ec319f672fb6c0a1463
Author: Philip Withnall <philip tecnocode co uk>
Date: Wed Jun 3 17:30:25 2009 +0100
Bug 584737 â?? String parsing is locale-sensitive
Replace some uses of strtod() with g_ascii_strtod() so that string parsing
isn't locale-dependent. Add a test case. Closes: bgo#584737
---
gdata/gdata-media-rss.c | 7 +++----
gdata/services/youtube/gdata-youtube-video.c | 2 +-
gdata/tests/general.c | 20 ++++++++++++++++++++
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/gdata/gdata-media-rss.c b/gdata/gdata-media-rss.c
index 6615f7b..582b2f2 100644
--- a/gdata/gdata-media-rss.c
+++ b/gdata/gdata-media-rss.c
@@ -274,8 +274,7 @@ gdata_media_thumbnail_new (const gchar *uri, guint width, guint height, gint64 _
* gdata_media_thumbnail_parse_time:
* @time_string: a time string to parse
*
- * Parses a time string in NTP format into a number of milliseconds since the
- * start of a media stream.
+ * Parses a time string in (a subset of) NTP format into a number of milliseconds since the start of a media stream.
*
* For more information about NTP format, see <ulink type="http" url="http://www.ietf.org/rfc/rfc2326.txt">RFC 2326 3.6 Normal Play Time</ulink>.
*
@@ -287,7 +286,7 @@ gint64
gdata_media_thumbnail_parse_time (const gchar *time_string)
{
guint hours, minutes;
- gfloat seconds;
+ gdouble seconds;
gchar *end_pointer;
g_return_val_if_fail (time_string != NULL, 0);
@@ -300,7 +299,7 @@ gdata_media_thumbnail_parse_time (const gchar *time_string)
if (end_pointer != time_string + 5)
return -1;
- seconds = strtod (time_string + 6, &end_pointer);
+ seconds = g_ascii_strtod (time_string + 6, &end_pointer);
if (end_pointer != time_string + strlen (time_string))
return -1;
diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c
index 4b87cf5..f498731 100644
--- a/gdata/services/youtube/gdata-youtube-video.c
+++ b/gdata/services/youtube/gdata-youtube-video.c
@@ -908,7 +908,7 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
if (average == NULL)
average_double = 0;
else
- average_double = strtod ((gchar*) average, NULL);
+ average_double = g_ascii_strtod ((gchar*) average, NULL);
xmlFree (average);
gdata_gd_rating_free (self->priv->rating);
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index c5c3108..e00f2ad 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -18,6 +18,7 @@
*/
#include <glib.h>
+#include <locale.h>
#include "gdata.h"
@@ -236,6 +237,23 @@ test_color_output (void)
g_free (color_string);
}
+static void
+test_media_thumbnail_parse_time (const gchar *locale)
+{
+ g_test_bug ("584737");
+
+ g_test_message ("Testing gdata_media_thumbnail_parse_time in the \"%s\" locale...", locale);
+ g_assert_cmpstr (setlocale (LC_ALL, locale), ==, locale);
+
+ g_assert_cmpint (gdata_media_thumbnail_parse_time ("00:01:42.500"), ==, 102500);
+ g_assert_cmpint (gdata_media_thumbnail_parse_time ("00:02:45"), ==, 165000);
+ g_assert_cmpint (gdata_media_thumbnail_parse_time ("12:00:15.000"), ==, 43215000);
+ g_assert_cmpint (gdata_media_thumbnail_parse_time ("00:00:00"), ==, 0);
+ g_assert_cmpint (gdata_media_thumbnail_parse_time ("foobar"), ==, -1);
+
+ setlocale (LC_ALL, "");
+}
+
int
main (int argc, char *argv[])
{
@@ -248,6 +266,8 @@ main (int argc, char *argv[])
g_test_add_func ("/query/categories", test_query_categories);
g_test_add_func ("/color/parsing", test_color_parsing);
g_test_add_func ("/color/output", test_color_output);
+ g_test_add_data_func ("/media/thumbnail/parse_time", "", test_media_thumbnail_parse_time);
+ g_test_add_data_func ("/media/thumbnail/parse_time", "de_DE", test_media_thumbnail_parse_time);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]