# JSON ampersand patch

- Thread: https://externals.io/message/29079
- Original archive: https://news-web.php.net/php.internals/29079
- Started by Tyler Lawson on 2007-04-27T19:39:34+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #29079 — Tyler Lawson — 2007-04-27T19:39:34+00:00

URL: https://externals.io/message/29079#29079

Hello,

I hope this is the right place for this, as I'd like to post a patch for
your consideration to the way the JSON handles ampersands.  I have had
problems sending JSON data back and forth over POST requests, where an
ampersand separates variables.  This patch will convert "&" into "\u0026",
which will allow ampersands to travel freely and be parsed by any valid JSON
decoder.

This has been applied against php-5.2.1

--- json.c      2007-01-12 07:17:32.000000000 -0500
+++ my_json.c    2007-04-27 15:12:44.000000000 -0400
@@ -301,6 +301,11 @@
                     smart_str_appendl(buf, "\\t", 2);
                 }
                 break;
+            case '&':
+                {
+                    smart_str_appendl(buf, "\\u0026", 6);
+                }
+                break;
             default:
                 {
                     if (us < ' ' || (us & 127) == us)


Tyler

---

## #29080 — Antony Dovgal — 2007-04-27T19:58:40+00:00

URL: https://externals.io/message/29079#29080 · In reply to: #29079

> Hello,
> 
> I hope this is the right place for this, as I'd like to post a patch for
> your consideration to the way the JSON handles ampersands.  I have had
> problems sending JSON data back and forth over POST requests, where an
> ampersand separates variables.  This patch will convert "&" into "\u0026",
> which will allow ampersands to travel freely and be parsed by any valid JSON
> decoder.

I believe a short reproduce case would explain it better.
 
> This has been applied against php-5.2.1
> 
> --- json.c      2007-01-12 07:17:32.000000000 -0500
> +++ my_json.c    2007-04-27 15:12:44.000000000 -0400
> @@ -301,6 +301,11 @@
>                      smart_str_appendl(buf, "\\t", 2);
>                  }
>                  break;
> +            case '&':
> +                {
> +                    smart_str_appendl(buf, "\\u0026", 6);
> +                }
> +                break;
>              default:
>                  {
>                      if (us < ' ' || (us & 127) == us)
> 
> 
> Tyler
> 


-- 
Wbr, 
Antony Dovgal
