Skip to content

Commit cadca24

Browse files
authored
msvs.py: Use floor division when escaping command-line arguments (#338)
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 "<python-input-3>", line 1, in <module> _EscapeCommandLineArgumentForMSBuild(s) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ File "<python-input-1>", line 11, in _EscapeCommandLineArgumentForMSBuild s = quote_replacer_regex2.sub(_Replace, s) File "<python-input-1>", 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\\"'
1 parent 147fa1a commit cadca24

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pylib/gyp/generator/msvs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def _EscapeCommandLineArgumentForMSBuild(s):
857857
"""Escapes a Windows command-line argument for use by MSBuild."""
858858

859859
def _Replace(match):
860-
return (len(match.group(1)) / 2 * 4) * "\\" + '\\"'
860+
return (len(match.group(1)) // 2 * 4) * "\\" + '\\"'
861861

862862
# Escape all quotes so that they are interpreted literally.
863863
s = quote_replacer_regex2.sub(_Replace, s)

0 commit comments

Comments
 (0)