Skip to content

Keep '#' in unquoted CLI values instead of treating it as a comment - #691

Open
DSeaStar wants to merge 1 commit into
google:masterfrom
DSeaStar:keep-hash-in-cli-values
Open

Keep '#' in unquoted CLI values instead of treating it as a comment#691
DSeaStar wants to merge 1 commit into
google:masterfrom
DSeaStar:keep-hash-in-cli-values

Conversation

@DSeaStar

Copy link
Copy Markdown

Fixes #338.

DefaultParseValue parses CLI args with ast.parse, which treats # as the start of a Python comment. Unquoted values were therefore truncated:

python test.py hi#there      # became "hi"
python test.py "hi#there"    # still became "hi"

That is an unintended side effect of using the AST (as noted on the issue). The existing parser test even called the strip "behavior [that] may change in the future."

If tokenize sees a # comment token (i.e. the hash is not inside a string literal), keep the original string. Quoted forms such as "0#comments" still parse as the string 0#comments.

Test plan

  • pytest fire/parser_test.py (20 passed)
  • Added cases for hi#there, path#ref, and 0#comments

ast.parse strips '#...' as a Python comment, so values like hi#there
were silently truncated. If tokenize sees a comment token, keep the
original string so hashes and fragments survive (issue google#338).
@google-cla

google-cla Bot commented Aug 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arg parsing truncates at hash

1 participant