msvs.py: Use floor division when escaping command-line arguments#338
Open
msvs.py: Use floor division when escaping command-line arguments#338
Conversation
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\\"'
There was a problem hiding this comment.
Pull request overview
This PR fixes a Python 3 runtime error in the MSBuild command-line argument escaping logic used by the MSVS generator, restoring the intended integer-division behavior from Python 2.
Changes:
- Replace
/with//in_EscapeCommandLineArgumentForMSBuildto avoid producing a float and triggering aTypeErrorwhen multiplying strings.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes nodejs/node-gyp#3296
%
python3.14