Commit b746794
committed
Handle leading whitespace in JSON body
Issue:
When sending JSON in the body of a POST
request from an HTML form - for creating
a new record, a new record was being created,
but with null as the value for all the fields,
instead of the values supplied.
Cause:
The template text in the textarea field, in the
HTML form had some leading whitespace. On looking
through the source, json_decode is being called
only if the first character of the $data variable
is a '{' or a '['.
JSON Specification RFC4627
https://tools.ietf.org/html/rfc4627#section-2
says that insignificant
whitespace is allowed before or after any of the
six structural characters - '{','[',']','}',':',','
where whitespace is defined as:
ws = *(
%x20 / ; Space
%x09 / ; Horizontal tab
%x0A / ; Line feed or New line
%x0D ; Carriage return
)
Fix:
trim the above characters from the beginning and ending
of the received data before checking that the first
character is a '[' or '{'1 parent 9bbc5bb commit b746794
2 files changed
+11
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1679 | 1679 | | |
1680 | 1680 | | |
1681 | 1681 | | |
| 1682 | + | |
1682 | 1683 | | |
1683 | 1684 | | |
1684 | 1685 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
646 | 656 | | |
0 commit comments