fix(scan): leave the browser-parser NaN parse to the resolver parity fix
The scan fallback's legacy-page parse (parse_page_json in _graph_prompt_text) is owned by the resolver parity change, which adds the same helper with the legacy pages' exact rule (NaN reads as null, Infinity still rejected). This branch keeps only the strict serialization of stored and answered JSON.
This commit is contained in:
@@ -28,7 +28,6 @@ __all__ = [
|
||||
"extract_generation_params",
|
||||
"extract_from_records",
|
||||
"parse_js_json",
|
||||
"parse_page_json",
|
||||
]
|
||||
|
||||
PLACEHOLDERS = MappingProxyType(
|
||||
@@ -954,29 +953,6 @@ def parse_js_json(text):
|
||||
return None
|
||||
|
||||
|
||||
def _null_constant(_name):
|
||||
return None
|
||||
|
||||
|
||||
def parse_page_json(text):
|
||||
"""A metadata record as the legacy pages parse it, or None where they fail.
|
||||
|
||||
The gallery, admin and metadata pages replace ComfyUI's ``NaN`` with
|
||||
``null`` before ``JSON.parse``. Here every non-finite literal ComfyUI
|
||||
writes (``NaN``, ``Infinity``, ``-Infinity``) is null, and only where it is
|
||||
a number: unlike the pages' text replacement, a prompt that spells "NaN"
|
||||
keeps its text.
|
||||
"""
|
||||
if not isinstance(text, str):
|
||||
return None
|
||||
try:
|
||||
return json.loads(
|
||||
text, parse_constant=_null_constant, parse_int=_double_integer
|
||||
)
|
||||
except (ValueError, RecursionError):
|
||||
return None
|
||||
|
||||
|
||||
def extract_from_records(prompt_text, workflow_text):
|
||||
"""``extract_generation_params`` for raw ``prompt``/``workflow`` record text.
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ ComfyUI writes its metadata with Python's default ``json.dumps``, so a graph can
|
||||
hold ``NaN``, ``Infinity`` and ``-Infinity`` (an ``IS_CHANGED`` that returns
|
||||
``float("nan")`` puts ``"is_changed": [NaN]`` into every saved prompt). Those
|
||||
literals are not JSON: browsers' ``JSON.parse`` and ``allow_nan=False`` reject
|
||||
them. Python's ``json.loads`` already accepts them, so reading needs no help;
|
||||
whatever PromptManager stores or answers as JSON goes through ``dumps_strict``,
|
||||
which writes each non-finite number as ``null`` (the legacy pages' own
|
||||
replacement) and leaves strings, including the words ``NaN`` or ``Infinity``
|
||||
inside prompt text, untouched.
|
||||
them. Reading follows the legacy pages (``parse_page_json`` where the browser
|
||||
parser is mirrored; Python's ``json.loads`` elsewhere). Whatever PromptManager
|
||||
stores or answers as JSON goes through ``dumps_strict``, which writes each
|
||||
non-finite number as ``null`` (the legacy pages' own replacement for NaN) and
|
||||
leaves strings, including the words ``NaN`` or ``Infinity`` inside prompt
|
||||
text, untouched.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
Reference in New Issue
Block a user