diff options
| author | Pip Cet | 2025-03-28 02:33:19 +0000 |
|---|---|---|
| committer | Pip Cet | 2025-03-30 11:52:07 +0000 |
| commit | 67e34f0ed8f6d3bbc78187a18f71010c70e10426 (patch) | |
| tree | c7595be84f8044a7704f44158b7131fc89a05ab0 /test/src/json-tests.el | |
| parent | 209b7e7444df5cb164679c0e55f46cba424ad13c (diff) | |
| download | emacs-67e34f0ed8f6d3bbc78187a18f71010c70e10426.tar.gz emacs-67e34f0ed8f6d3bbc78187a18f71010c70e10426.zip | |
Respect narrowed buffers when parsing JSON (bug#77325)
* src/json.c (Fjson_insert): Simplify 'memcpy' argument.
(Fjson_parse_buffer): Only read to ZV, not all the way to Z.
* test/src/json-tests.el (with-all-gap-positions-in-temp-buffer):
New macro.
(json-parse-buffer/restricted): New test.
Diffstat (limited to 'test/src/json-tests.el')
| -rw-r--r-- | test/src/json-tests.el | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el index 94b6cfcffca..1cb667ddeac 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el | |||
| @@ -315,6 +315,32 @@ Test with both unibyte and multibyte strings." | |||
| 315 | (should-not (bobp)) | 315 | (should-not (bobp)) |
| 316 | (should (looking-at-p (rx " [456]" eos))))) | 316 | (should (looking-at-p (rx " [456]" eos))))) |
| 317 | 317 | ||
| 318 | (defmacro with-all-gap-positions-in-temp-buffer (string &rest body) | ||
| 319 | "Create a temporary buffer containing STRING, and evaluate BODY | ||
| 320 | with each possible gap position. | ||
| 321 | See also `with-temp-buffer'." | ||
| 322 | `(with-temp-buffer | ||
| 323 | (insert ,string) | ||
| 324 | (dotimes (i (- (point-max) (point-min))) | ||
| 325 | (goto-char (- (point-max) i)) | ||
| 326 | (insert "X") | ||
| 327 | (delete-region (1- (point)) (point)) | ||
| 328 | ,@body))) | ||
| 329 | |||
| 330 | (ert-deftest json-parse-buffer/restricted () | ||
| 331 | (with-all-gap-positions-in-temp-buffer | ||
| 332 | "[123] [456] [789]" | ||
| 333 | (pcase-dolist (`((,beg . ,end) ,result) | ||
| 334 | '(((7 . 12) [456]) | ||
| 335 | ((1 . 6) [123]) | ||
| 336 | ((13 . 18) [789]))) | ||
| 337 | (goto-char beg) | ||
| 338 | (narrow-to-region beg end) | ||
| 339 | (should (equal (json-parse-buffer) result)) | ||
| 340 | (should (= (point) end)) | ||
| 341 | (should-error (json-parse-buffer) :type 'json-end-of-file) | ||
| 342 | (widen)))) | ||
| 343 | |||
| 318 | (ert-deftest json-parse-with-custom-null-and-false-objects () | 344 | (ert-deftest json-parse-with-custom-null-and-false-objects () |
| 319 | (let* ((input | 345 | (let* ((input |
| 320 | "{ \"abc\" : [9, false] , \"def\" : null }") | 346 | "{ \"abc\" : [9, false] , \"def\" : null }") |