[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string-to-unibyte in image-jpeg-p
From: |
Stefan Monnier |
Subject: |
Re: string-to-unibyte in image-jpeg-p |
Date: |
Wed, 23 May 2018 15:43:10 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> One of the last ‘string-to-unibyte’ (deprecated for a while)
> calls is in ‘image-jpeg-p’:
>
> (defun image-jpeg-p (data)
> "..."
> (setq data (ignore-errors (string-to-unibyte data)))
> ...)
To figure out the best fix, we need to know:
- Why are errors ignored?
- Why/when is data a multibyte string?
> We can simulate ‘string-to-unibyte’ (except for error message
> particulars) with ‘FAKE-string-to-unibyte’, which uses the
> modern ‘encode-coding-string’:
>
> (defun FAKE-string-to-unibyte (s)
> (let ((tem (encode-coding-string s 'binary)))
> (when (string-match-p "\xc2" tem)
> (error "badness"))
You can't really detect a "non-ascii non-rawbyte input" by looking at
the output of encode-coding-string, so this is not the right approach.
You could try something like:
(unless (unibyte-string-p data)
(setq data
;; \x3fffnn encode "raw bytes" in multibyte strings.
(if (string-match "[^\x00-\xff\x3fff80-\x3fffff]" data)
nil
(encode-coding-string data 'binary))))
> - If so, which branch gets the change, ‘emacs-26’ or ‘master’?
Definitely not emacs-26
Stefan
- string-to-unibyte in image-jpeg-p, Thien-Thi Nguyen, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p,
Stefan Monnier <=
- Re: string-to-unibyte in image-jpeg-p, Eli Zaretskii, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Andreas Schwab, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Stefan Monnier, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Paul Eggert, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Robert Pluim, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Eli Zaretskii, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Robert Pluim, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Eli Zaretskii, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Stefan Monnier, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Eli Zaretskii, 2018/05/25