1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-29 07:58:28 +00:00

Fix encoding with 'utf-8-auto'

* src/coding.c (encode_coding_utf_8): Fix encoding with
'utf-8-auto': it should produce BOM, per the documentation of
the :bom attribute.  (Bug#60750)

* lisp/international/mule.el (define-coding-system): Doc fix.

* test/src/coding-tests.el (coding-tests): Use
'with-coding-priority' instead of 'prefer-coding-system', as the
latter has global persistent effect and affects further tests.
This commit is contained in:
Eli Zaretskii 2023-01-12 16:36:35 +02:00
parent 53b47df822
commit cfd2b3504a
3 changed files with 18 additions and 17 deletions

View File

@ -863,7 +863,8 @@ This attribute is meaningful only when `:coding-type' is `utf-16' or
VALUE must be `big' or `little' specifying big-endian and VALUE must be `big' or `little' specifying big-endian and
little-endian respectively. The default value is `big'. little-endian respectively. The default value is `big'.
This attribute is meaningful only when `:coding-type' is `utf-16'. Changing this attribute is only meaningful when `:coding-type'
is `utf-16'.
`:ccl-decoder' (required if :coding-type is `ccl') `:ccl-decoder' (required if :coding-type is `ccl')

View File

@ -1431,7 +1431,7 @@ encode_coding_utf_8 (struct coding_system *coding)
ptrdiff_t produced_chars = 0; ptrdiff_t produced_chars = 0;
int c; int c;
if (CODING_UTF_8_BOM (coding) == utf_with_bom) if (CODING_UTF_8_BOM (coding) != utf_without_bom)
{ {
ASSURE_DESTINATION (3); ASSURE_DESTINATION (3);
EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3); EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3);

View File

@ -148,21 +148,21 @@
(defun coding-tests (content-type write-coding read-coding detected-coding (defun coding-tests (content-type write-coding read-coding detected-coding
&optional translator) &optional translator)
(prefer-coding-system 'utf-8-auto) (with-coding-priority '(utf-8-auto)
(let ((filename (coding-tests-filename content-type write-coding))) (let ((filename (coding-tests-filename content-type write-coding)))
(with-temp-buffer (with-temp-buffer
(let ((coding-system-for-read read-coding) (let ((coding-system-for-read read-coding)
(contents (coding-tests-file-contents content-type)) (contents (coding-tests-file-contents content-type))
(disable-ascii-optimization nil)) (disable-ascii-optimization nil))
(if translator (if translator
(setq contents (funcall translator contents))) (setq contents (funcall translator contents)))
(insert-file-contents filename) (insert-file-contents filename)
(if (and (coding-system-equal buffer-file-coding-system detected-coding) (if (and (coding-system-equal buffer-file-coding-system detected-coding)
(string= (buffer-string) contents)) (string= (buffer-string) contents))
nil nil
(list buffer-file-coding-system (list buffer-file-coding-system
(string-to-list (buffer-string)) (string-to-list (buffer-string))
(string-to-list contents))))))) (string-to-list contents))))))))
(ert-deftest ert-test-coding-ascii () (ert-deftest ert-test-coding-ascii ()
(unwind-protect (unwind-protect