]> sjero.net Git - wget/blobdiff - src/iri.c
Do not free/duplicate current/remote encoding string if they aren't changed
[wget] / src / iri.c
index 5108d999c01561832f81dbe2f20e0b634bbe4e15..d23615ae7fb4942de22f8ac5a68ddff9f17d10d3 100644 (file)
--- a/src/iri.c
+++ b/src/iri.c
@@ -41,6 +41,9 @@ as that of the covered work.  */
 #include "utils.h"
 #include "iri.h"
 
+/* RFC3987 section 3.1 mandates STD3 ASCII RULES */
+#define IDNA_FLAGS  IDNA_USE_STD3_ASCII_RULES
+
 /* Note: locale encoding is kept in options struct (opt.locale) */
 
 /* Hold the encoding used for the current fetch */
@@ -254,7 +257,7 @@ idn_encode (char *host, bool utf8_encoded)
     }
 
   /* toASCII UTF-8 NULL terminated string */
-  ret = idna_to_ascii_8z (host, &new, 0);
+  ret = idna_to_ascii_8z (host, &new, IDNA_FLAGS);
   if (ret != IDNA_SUCCESS)
     {
       /* sXXXav : free new when needed ! */
@@ -274,7 +277,7 @@ idn_decode (char *host)
   char *new;
   int ret;
 
-  ret = idna_to_unicode_8zlz (host, &new, 0);
+  ret = idna_to_unicode_8zlz (host, &new, IDNA_FLAGS);
   if (ret != IDNA_SUCCESS)
     {
       logprintf (LOG_VERBOSE, "idn_decode failed (%d): %s\n", ret,
@@ -334,18 +337,27 @@ void set_current_charset (char *charset)
 {
   /*printf("[ current = `%s'\n", charset);*/
   if (current)
-    xfree (current);
+    {
+      /* Do nothing if already equal */
+      if (!strcasecmp (current, charset))
+        return;
+      xfree (current);
+    }
 
   current = charset ? xstrdup (charset) : NULL;
 }
 
 void set_current_as_locale (void)
 {
+  /* sXXXav : assert opt.locale NULL ? */
   /*printf("[ current = locale = `%s'\n", opt.locale);*/
   if (current)
-    xfree (current);
+    {
+      if (!strcasecmp (current, opt.locale))
+        return;
+      xfree (current);
+    }
 
-  /* sXXXav : assert opt.locale NULL ? */
   current = xstrdup (opt.locale);
 }
 
@@ -354,8 +366,12 @@ set_remote_charset (char *charset)
 {
   /*printf("[ remote = `%s'\n", charset);*/
   if (remote)
-    xfree (remote);
-
+    {
+      /* Do nothing if already equal */
+      if (!strcasecmp (remote, charset))
+        return;
+      xfree (remote);
+    }
   remote = charset ? xstrdup (charset) : NULL;
 }
 
@@ -364,7 +380,12 @@ set_remote_as_current (void)
 {
   /*printf("[ remote = current = `%s'\n", current);*/
   if (remote)
-    xfree (remote);
+    {
+      /* Do nothing if already equal */
+      if (current && !strcasecmp (remote, current))
+        return;
+      xfree (remote);
+    }
 
   remote = current ? xstrdup (current) : NULL;
 }
@@ -381,7 +402,7 @@ void set_utf8_encode (bool encode)
 
 bool get_utf8_encode (void)
 {
-  return utf8_encode;
+  return (!ugly_no_encode && utf8_encode);
 }
 
 void set_ugly_no_encode (bool ugly)
@@ -389,8 +410,3 @@ void set_ugly_no_encode (bool ugly)
   ugly_no_encode = ugly;
 }
 
-bool get_ugly_no_encode (void)
-{
-  return ugly_no_encode;
-}
-