From d796a73a73d62db48c1d8f9bb1691fa3f92d5aec Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Thu, 10 Oct 2013 21:26:47 +0300 Subject: [PATCH] quvi-dump: Do not escape reserved chars in URLs Other: * Escape UTF8 chars in the URLs (lprint:{rfc2483,json}) See also: * https://tools.ietf.org/html/rfc3986#section-2.2 * https://en.wikipedia.org/wiki/Percent-encoding Signed-off-by: Toni Gundogdu --- src/main.c | 2 ++ src/print/json_print.c | 8 +++++--- src/print/rfc2483_print.c | 6 ++++-- src/print/xml_print.c | 9 +++++++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index a0a2986..db0fe12 100644 --- a/src/main.c +++ b/src/main.c @@ -29,6 +29,8 @@ #include "opts.h" #include "cmd.h" +const gchar *reserved_chars = "!*'();:@&=+$,/?#[]"; + struct opts_s opts; gint exit_status; gchar *argv0; diff --git a/src/print/json_print.c b/src/print/json_print.c index 6df652b..c62796f 100644 --- a/src/print/json_print.c +++ b/src/print/json_print.c @@ -103,6 +103,8 @@ static gint _print_buffer(const json_t p) return (EXIT_SUCCESS); } +extern const gchar *reserved_chars; + void lprint_json_errmsg(const gchar *fmt, ...) { va_list args; @@ -111,7 +113,7 @@ void lprint_json_errmsg(const gchar *fmt, ...) va_start(args, fmt); if (g_vasprintf(&s, fmt, args) >0) { - gchar *e = g_uri_escape_string(s, NULL, TRUE); + gchar *e = g_uri_escape_string(s, reserved_chars, FALSE); g_printerr("{\"error\" : \"%s\"}\n", e); g_free(e); g_free(s); @@ -158,7 +160,7 @@ static gint _set_member(const json_t p, const lutilPropertyType pt, json_builder_set_member_name(p->b, n); if (s != NULL) { - gchar *e = g_uri_escape_string(s, NULL, TRUE); + gchar *e = g_uri_escape_string(s, reserved_chars, FALSE); json_builder_add_string_value(p->b, e); g_free(e); } @@ -455,7 +457,7 @@ gint lprint_json_scan_properties(quvi_scan_t qs, gpointer data) json_builder_begin_object(p->b); json_builder_set_member_name(p->b, "url"); - e = g_uri_escape_string(s, NULL, TRUE); + e = g_uri_escape_string(s, reserved_chars, FALSE); json_builder_add_string_value(p->b, e); json_builder_end_object(p->b); diff --git a/src/print/rfc2483_print.c b/src/print/rfc2483_print.c index 087601a..a2269c2 100644 --- a/src/print/rfc2483_print.c +++ b/src/print/rfc2483_print.c @@ -70,6 +70,8 @@ static gint _rfc2483_handle_free(gpointer data, const gint r) return (r); } +extern const gchar *reserved_chars; + static gint _print(const rfc2483_t p, const lutilPropertyType pt, const gchar *n, const gchar *s, const gdouble d, const gboolean comment_out, const gboolean escape) @@ -87,7 +89,7 @@ static gint _print(const rfc2483_t p, const lutilPropertyType pt, { if (escape == TRUE) { - gchar *e = g_uri_escape_string(s, NULL, TRUE); + gchar *e = g_uri_escape_string(s, reserved_chars, FALSE); g_print("%s%s\n", h, e); g_free(e); } @@ -275,7 +277,7 @@ gint lprint_rfc2483_scan_properties(quvi_scan_t qs, gpointer data) g_print(_("# Embedded media URLs\n#\n")); while ( (s = quvi_scan_next_media_url(qs)) != NULL) { - gchar *e = g_uri_escape_string(s, NULL, TRUE); + gchar *e = g_uri_escape_string(s, reserved_chars, FALSE); g_print("%s\n", e); g_free(e); } diff --git a/src/print/xml_print.c b/src/print/xml_print.c index 29d23a2..5917e6a 100644 --- a/src/print/xml_print.c +++ b/src/print/xml_print.c @@ -141,15 +141,20 @@ static gint _end_e(const xml_t p, const ErrorMessage e, const gchar *w) return (r); } +extern const gchar *reserved_chars; + static gint _write_attr(const xml_t p, const gchar *n, const gchar *s) { xmlChar *e; gint r; - e = xmlURIEscapeStr(BAD_CAST s, NULL); + e = xmlURIEscapeStr(BAD_CAST s, BAD_CAST reserved_chars); + + r = (xmlTextWriterWriteAttribute(p->w, BAD_CAST n, e) <0) ? EXIT_FAILURE : EXIT_SUCCESS; + xmlFree(e); if (r != EXIT_SUCCESS) @@ -206,7 +211,7 @@ void lprint_xml_errmsg(const gchar *fmt, ...) va_start(args, fmt); if (g_vasprintf(&s, fmt, args) >0) { - xmlChar *e = xmlURIEscapeStr(BAD_CAST s, NULL); + xmlChar *e = xmlURIEscapeStr(BAD_CAST s, BAD_CAST reserved_chars); g_printerr("" "", e); xmlFree(e); -- 2.11.4.GIT