From c5b8261dde6998629ef192691fa2584524062eb7 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 10 Apr 2026 09:44:34 +0200 Subject: [PATCH] msvs.py: Use floor division when escaping command-line arguments Fixes nodejs/node-gyp#3296 * nodejs/node-gyp#3296 % `python3.14` ``` >>> import re >>> s = "TEST_STRING=\\\"TEST\\\"" >>> quote_replacer_regex2 = re.compile(r'(\\+)"') ... ... ... def _EscapeCommandLineArgumentForMSBuild(s): ... """Escapes a Windows command-line argument for use by MSBuild.""" ... ... def _Replace(match): ... return (len(match.group(1)) / 2 * 4) * "\\" + '\\"' ... ... # Escape all quotes so that they are interpreted literally. ... s = quote_replacer_regex2.sub(_Replace, s) ... return s ... >>> _EscapeCommandLineArgumentForMSBuild(s) Traceback (most recent call last): File "", line 1, in _EscapeCommandLineArgumentForMSBuild(s) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ File "", line 11, in _EscapeCommandLineArgumentForMSBuild s = quote_replacer_regex2.sub(_Replace, s) File "", line 8, in _Replace return (len(match.group(1)) / 2 * 4) * "\\" + '\\"' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~ TypeError: can't multiply sequence by non-int of type 'float' >>> Modify _Replace() to use floor division... >>> _EscapeCommandLineArgumentForMSBuild(s) 'TEST_STRING=\\"TEST\\"' --- pylib/gyp/generator/msvs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylib/gyp/generator/msvs.py b/pylib/gyp/generator/msvs.py index 0f14c055..42bee33d 100644 --- a/pylib/gyp/generator/msvs.py +++ b/pylib/gyp/generator/msvs.py @@ -857,7 +857,7 @@ def _EscapeCommandLineArgumentForMSBuild(s): """Escapes a Windows command-line argument for use by MSBuild.""" def _Replace(match): - return (len(match.group(1)) / 2 * 4) * "\\" + '\\"' + return (len(match.group(1)) // 2 * 4) * "\\" + '\\"' # Escape all quotes so that they are interpreted literally. s = quote_replacer_regex2.sub(_Replace, s)