Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OpenAI API keys passed as multibyte strings #44

Merged
merged 1 commit into from
Apr 12, 2024
Merged

fix: OpenAI API keys passed as multibyte strings #44

merged 1 commit into from
Apr 12, 2024

Commits on Apr 12, 2024

  1. fix: OpenAI API keys passed as multibyte strings

    Emacs has two types of strings: multibyte and unibyte. The request library is
    essentially a giant ‘concat’ call, which converts the entire result to multibyte
    if any single component is multibyte, including the headers. Even if you encoded
    the body: that effect will be spoiled by a single multibyte header string. This
    is regardless of the header actually containing multibyte characters: while an
    Emacs string literal containing only simple characters will be unibyte, an API
    key fetched from an external source will often be multibyte,
    e.g. ‘shell-command-to-string’.
    
    Example:
    
    (dolist (x (list
                "x"
                (shell-command-to-string "printf x")
                (encode-coding-string (shell-command-to-string "printf x") 'utf-8)))
      (let ((s (concat x (encode-coding-string "é" 'utf-8))))
        (message
         "%S: %s(%s) %s, %s"
         s
         (multibyte-string-p s)
         (multibyte-string-p x)
         (string-bytes s)
         (length s))))
    
    Output:
    
    "x\303\251": nil(nil) 3, 3
    "x\303\251": t(t) 5, 3
    "x\303\251": nil(nil) 3, 3
    
    And:
    
    (multibyte-string-p "foo") ; NIL
    (multibyte-string-p "fôo") ; T
    hraban committed Apr 12, 2024
    Configuration menu
    Copy the full SHA
    1332281 View commit details
    Browse the repository at this point in the history