From: Mattias EngdegÄrd Date: Sat, 17 Jun 2023 09:55:12 +0000 (+0200) Subject: ; * src/treesit.c (treesit_query_string_string): fix last change X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c279369a7a9e373bb4b88feff0a05f56f3c0fa3b;p=emacs.git ; * src/treesit.c (treesit_query_string_string): fix last change Escape the backslash character itself. --- diff --git a/src/treesit.c b/src/treesit.c index 680e510b74d..87aa1eeb377 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2312,7 +2312,8 @@ treesit_query_string_string (Lisp_Object str) for (ptrdiff_t i = 0; i < nbytes; i++) { unsigned char c = SREF (str, i); - escapes += (c == '\0' || c == '\n' || c == '\r' || c == '\t' || c == '"'); + escapes += (c == '\0' || c == '\n' || c == '\r' || c == '\t' + || c == '"' || c == '\\'); } ptrdiff_t nchars = SCHARS (str); ptrdiff_t extra = escapes + 2; /* backslashes + double quotes */ @@ -2331,7 +2332,8 @@ treesit_query_string_string (Lisp_Object str) case '\n': *d++ = '\\'; *d++ = 'n'; break; case '\r': *d++ = '\\'; *d++ = 'r'; break; case '\t': *d++ = '\\'; *d++ = 't'; break; - case '"': *d++ = '\\'; *d++ = '"'; break; + case '"': + case '\\': *d++ = '\\'; *d++ = c; break; default: *d++ = c; break; } } diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el index 6e7d0fc48d2..34540b463cd 100644 --- a/test/src/treesit-tests.el +++ b/test/src/treesit-tests.el @@ -465,8 +465,8 @@ BODY is the test body." ;; Test string conversion in `treesit-pattern-expand'. (should (equal - (treesit-pattern-expand "a\nb\rc\td\0e\"f\1g") - "\"a\\nb\\rc\\td\\0e\\\"f\1g\""))))) + (treesit-pattern-expand "a\nb\rc\td\0e\"f\1g\\h\fi") + "\"a\\nb\\rc\\td\\0e\\\"f\1g\\\\h\fi\""))))) ;;; Narrow