diff options
| author | Paul Eggert | 2018-10-10 23:17:18 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-10-10 23:19:42 -0700 |
| commit | 5bd8cfc14d4b0c78c07e65a583f42a10c4cbc06d (patch) | |
| tree | c51b2a470f62679f5e5c3f6f55d90aa0082d0133 /test | |
| parent | fd3a48fcd8bb212ec12b9b10a79de0ae605ee93b (diff) | |
| download | emacs-5bd8cfc14d4b0c78c07e65a583f42a10c4cbc06d.tar.gz emacs-5bd8cfc14d4b0c78c07e65a583f42a10c4cbc06d.zip | |
Fix mishandling of symbols that look like numbers
* src/bignum.c (make_neg_biguint): New function.
* src/lread.c (read1): Do not mishandle an unquoted symbol
with name equal to something like "1\0x", i.e., a string
of numeric form followed by a NUL byte.
Formerly these symbols were misread as numbers.
(string_to_number): Change last argument from an integer flag
to a pointer to the length. This lets the caller figure out
how much of the prefix was used. All callers changed.
Add a fast path if the integer (sans sign) fits in uintmax_t.
Update comments and simplify now that bignums are present.
* src/print.c (print_object): Fix quoting of symbols that look
like numbers, by relying on string_to_number for the tricky
cases rather than trying to redo its logic, incorrectly. For
example, (read (prin1-to-string '\1e+NaN)) formerly returned
"1e+NaN", which was wrong: a backslash is needed in the output
to prevent it from being read as a NaN. Escape NO_BREAK_SPACE
too, since lread.c treats it like SPACE.
* test/src/print-tests.el (print-read-roundtrip):
Add tests illustrating the abovementioned bugs.
Diffstat (limited to 'test')
| -rw-r--r-- | test/src/print-tests.el | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/test/src/print-tests.el b/test/src/print-tests.el index 091f1aa1afb..78e769f50e9 100644 --- a/test/src/print-tests.el +++ b/test/src/print-tests.el | |||
| @@ -95,8 +95,20 @@ otherwise, use a different charset." | |||
| 95 | "--------\n")))) | 95 | "--------\n")))) |
| 96 | 96 | ||
| 97 | (ert-deftest print-read-roundtrip () | 97 | (ert-deftest print-read-roundtrip () |
| 98 | (let ((sym '\’bar)) | 98 | (let ((syms (list '## '& '* '+ '- '/ '0E '0e '< '= '> 'E 'E0 'NaN '\" |
| 99 | (should (eq (read (prin1-to-string sym)) sym)))) | 99 | '\# '\#x0 '\' '\'\' '\( '\) '\+00 '\, '\-0 '\. '\.0 |
| 100 | '\0 '\0.0 '\0E0 '\0e0 '\1E+ '\1E+NaN '\1e+ '\1e+NaN | ||
| 101 | '\; '\? '\[ '\\ '\] '\` '_ 'a 'e 'e0 'x | ||
| 102 | '{ '| '} '~ : '\’ '\’bar | ||
| 103 | (intern "\t") (intern "\n") (intern " ") | ||
| 104 | (intern "\N{NO-BREAK SPACE}") | ||
| 105 | (intern "\N{ZERO WIDTH SPACE}") | ||
| 106 | (intern "\0")))) | ||
| 107 | (dolist (sym syms) | ||
| 108 | (should (eq (read (prin1-to-string sym)) sym)) | ||
| 109 | (dolist (sym1 syms) | ||
| 110 | (let ((sym2 (intern (concat (symbol-name sym) (symbol-name sym1))))) | ||
| 111 | (should (eq (read (prin1-to-string sym2)) sym2))))))) | ||
| 100 | 112 | ||
| 101 | (ert-deftest print-bignum () | 113 | (ert-deftest print-bignum () |
| 102 | (let* ((str "999999999999999999999999999999999") | 114 | (let* ((str "999999999999999999999999999999999") |