aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2023-01-12 16:36:35 +0200
committerEli Zaretskii2023-01-12 16:36:35 +0200
commitcfd2b3504ab5de6eb5f3c7a0784cb447883e1326 (patch)
tree05cd282566387e4c469e44830f50586dd56ae026
parent53b47df8229a3a54777940663edda28de0a01b90 (diff)
downloademacs-cfd2b3504ab5de6eb5f3c7a0784cb447883e1326.tar.gz
emacs-cfd2b3504ab5de6eb5f3c7a0784cb447883e1326.zip
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.
-rw-r--r--lisp/international/mule.el3
-rw-r--r--src/coding.c2
-rw-r--r--test/src/coding-tests.el30
3 files changed, 18 insertions, 17 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index 4f6addea387..eddd7b6407a 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -863,7 +863,8 @@ This attribute is meaningful only when `:coding-type' is `utf-16' or
863VALUE must be `big' or `little' specifying big-endian and 863VALUE must be `big' or `little' specifying big-endian and
864little-endian respectively. The default value is `big'. 864little-endian respectively. The default value is `big'.
865 865
866This attribute is meaningful only when `:coding-type' is `utf-16'. 866Changing this attribute is only meaningful when `:coding-type'
867is `utf-16'.
867 868
868`:ccl-decoder' (required if :coding-type is `ccl') 869`:ccl-decoder' (required if :coding-type is `ccl')
869 870
diff --git a/src/coding.c b/src/coding.c
index 4e59f2b6a1b..49dcd8634f3 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -1431,7 +1431,7 @@ encode_coding_utf_8 (struct coding_system *coding)
1431 ptrdiff_t produced_chars = 0; 1431 ptrdiff_t produced_chars = 0;
1432 int c; 1432 int c;
1433 1433
1434 if (CODING_UTF_8_BOM (coding) == utf_with_bom) 1434 if (CODING_UTF_8_BOM (coding) != utf_without_bom)
1435 { 1435 {
1436 ASSURE_DESTINATION (3); 1436 ASSURE_DESTINATION (3);
1437 EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3); 1437 EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3);
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el
index 6bd8d1ae6c4..b27907027ba 100644
--- a/test/src/coding-tests.el
+++ b/test/src/coding-tests.el
@@ -148,21 +148,21 @@
148 148
149(defun coding-tests (content-type write-coding read-coding detected-coding 149(defun coding-tests (content-type write-coding read-coding detected-coding
150 &optional translator) 150 &optional translator)
151 (prefer-coding-system 'utf-8-auto) 151 (with-coding-priority '(utf-8-auto)
152 (let ((filename (coding-tests-filename content-type write-coding))) 152 (let ((filename (coding-tests-filename content-type write-coding)))
153 (with-temp-buffer 153 (with-temp-buffer
154 (let ((coding-system-for-read read-coding) 154 (let ((coding-system-for-read read-coding)
155 (contents (coding-tests-file-contents content-type)) 155 (contents (coding-tests-file-contents content-type))
156 (disable-ascii-optimization nil)) 156 (disable-ascii-optimization nil))
157 (if translator 157 (if translator
158 (setq contents (funcall translator contents))) 158 (setq contents (funcall translator contents)))
159 (insert-file-contents filename) 159 (insert-file-contents filename)
160 (if (and (coding-system-equal buffer-file-coding-system detected-coding) 160 (if (and (coding-system-equal buffer-file-coding-system detected-coding)
161 (string= (buffer-string) contents)) 161 (string= (buffer-string) contents))
162 nil 162 nil
163 (list buffer-file-coding-system 163 (list buffer-file-coding-system
164 (string-to-list (buffer-string)) 164 (string-to-list (buffer-string))
165 (string-to-list contents))))))) 165 (string-to-list contents))))))))
166 166
167(ert-deftest ert-test-coding-ascii () 167(ert-deftest ert-test-coding-ascii ()
168 (unwind-protect 168 (unwind-protect