mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-04 02:03:59 +00:00
`switch_url_encode()` encodes with `double_encode` false, so a `%XX` already present in `json_text` was emitted unchanged and became indistinguishable from the escapes the body encoding added itself. Decoding the body then consumed the values' own escapes as well, and the document no longer parsed. Values arrive pre-encoded whenever `encode-values` is on, and can hold percent-hex text regardless of it. Encode with `switch_url_encode_opt(..., SWITCH_TRUE)` so `%` is encoded too and the body decodes back to exactly the serialized document. `mod_xml_cdr` and `mod_format_cdr` already encode their bodies this way. - Size the escape buffer `* 3 + 1`. `switch_url_encode_opt()` reserves the terminator from the length it is given, so `* 3` dropped the last escaped character when every byte needed encoding. The base64 call now takes that length directly. - Warn at load when `encode` and `encode-values` are both on, since the values stay encoded after the body is decoded. - Correct both encoding config comments; the `encode` one described only `base64`. Adds core coverage in `tests/unit/switch_utils.c` for both `switch_url_encode_opt()` modes, its output bounds, and a JSON body encoded and decoded once.
FreeSWITCH unit tests should be kept as shallow unit tests and micro benchmarks testing functionality exposed through libfreeswitch. Requirements for a new unit tests: 1. Tests must use switch_test.h framework