Skip to content

Fix fragile parameter parsing in concore.py and concoredocker.py#201

Open
GREENRAT-K405 wants to merge 3 commits intoControlCore-Project:devfrom
GREENRAT-K405:fix/fragile-parameter-parsing
Open

Fix fragile parameter parsing in concore.py and concoredocker.py#201
GREENRAT-K405 wants to merge 3 commits intoControlCore-Project:devfrom
GREENRAT-K405:fix/fragile-parameter-parsing

Conversation

@GREENRAT-K405
Copy link

@GREENRAT-K405 GREENRAT-K405 commented Feb 4, 2026

I have replaced the regex-based parameter parsing logic in concore.py and concoredocker.py with a deterministic key=value parser, eliminating data corruption and parse failures when parameter values contain spaces, =, or delimiters.

I have ensured backward compatibility by continuing to automatically convert numeric and structured values (e.g., int, float, list) using ast.literal_eval, while safely falling back to raw strings for values that cannot be evaluated (e.g., paths, URLs).

(This closes #184.)

Copilot AI review requested due to automatic review settings February 4, 2026 11:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the previous regex-based concore.params parsing in the Python runtime (concore.py) and Docker runtime (concoredocker.py) with explicit key=value parsing plus per-value ast.literal_eval coercion.

Changes:

  • Added parse_params(...) helper(s) to parse delimited key=value pairs and literal_eval values when possible.
  • Updated concore.params loading to call the new parser and simplified error handling/logging in both runtimes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
concore.py Introduces a semicolon-delimited parse_params and switches params loading to use it.
concoredocker.py Introduces a comma-delimited parse_params and switches params loading to use it with improved exception reporting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GREENRAT-K405
Copy link
Author

@pradeeban please review this before merging:

The original parsing logic in concore.py splits around ';' deliminater, whereas the concoredocker.py parsing logic splits around ',' comma was this intentional?
I have still kept this logic in my changes.
Please do let me know if this requires a quick fix!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +44 to +56
# keep backward compatibility: comma-separated params
for item in s.split(","):
if "=" in item:
key, value = item.split("=", 1)
key = key.strip()
value = value.strip()
#try to convert to python type (int, float, list, etc.)
# Use literal_eval to preserve backward compatibility (integers/lists)
# Fallback to string for unquoted values (paths, URLs)
try:
params[key] = literal_eval(value)
except (ValueError, SyntaxError):
params[key] = value
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_params splits on commas unconditionally (s.split(",")), which will corrupt values that legally contain commas (e.g., list literals like a=[1,2], CSV-like strings, or quoted strings containing commas). This contradicts the goal of supporting structured values via literal_eval. Consider implementing a delimiter-splitting routine that respects quotes/bracket nesting (or require full dict literals/JSON when values may contain commas).

Copilot uses AI. Check for mistakes.
Comment on lines +175 to +187
for item in s.split(";"):
if "=" in item:
key, value = item.split("=", 1) # split only once
key=key.strip()
value=value.strip()
#try to convert to python type (int, float, list, etc.)
# Use literal_eval to preserve backward compatibility (integers/lists)
# Fallback to string for unquoted values (paths, URLs)
try:
params[key] = literal_eval(value)
except (ValueError, SyntaxError):
params[key] = value
return params
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_params splits on ; without honoring quoting/escaping, so any value containing a semicolon (e.g., URLs or user strings) will be split into multiple items and parsed incorrectly. If semicolons are expected inside values, switch to a parser that tokenizes key/value pairs while tracking quote/bracket depth (or require dict/JSON literals for such cases).

Copilot uses AI. Check for mistakes.
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.

1 participant