Visitar URL original
Fix parse_mode flags without native or NaN number modes by ryanduguid · Pull Request #243 · python-rapidjson/python-rapidjson · GitHub
Skip to content

Fix parse_mode flags without native or NaN number modes - #243

Open
ryanduguid wants to merge 1 commit into
python-rapidjson:masterfrom
ryanduguid:fix-parse-mode-without-nan
Open

ryanduguid wants to merge 1 commit into
python-rapidjson:masterfrom
ryanduguid:fix-parse-mode-without-nan

Conversation

@ryanduguid

Copy link
Copy Markdown

Comments and trailing commas are not consistently honoured when number_mode is None, NM_NONE or NM_DECIMAL, or when allow_nan=False selects the same decoder path. The shared DECODE macro omits the comments-only branch and drops the trailing-comma flag when both extensions are requested.

For example, this raises JSONDecodeError on the base and returns [1.5] with the fix:

rapidjson.loads(
    '/* comment */[1.5,]',
    allow_nan=False,
    parse_mode=rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS,
)

The fix follows the existing flag-dispatch pattern, retaining kParseNumbersAsStringsFlag in both corrected selections. The tests reuse the six-form decoding fixture to cover loads, load and Decoder, plus the direct allow_nan=False routes. They check nested syntax, float/Decimal types, arbitrary-size integers, strict rejection and literal comment-like strings.

Verification

  • The 75 new cases produce 38 failures and 37 passes against unchanged C++ on Linux and Windows. The fixed full suite passes on Linux CPython 3.10.22, 3.13.16, 3.14.7 and 3.15.0rc3, and Windows CPython 3.13.13/MSVC 19.44: 1,006 passed, 17 skipped and two expected failures, with six additional version-conditional cases passing on 3.10.
  • make -C docs doctest and stubtest rapidjson pass on Linux 3.13; the configured Sphinx doctest command and stubtest pass on Windows 3.13. Both doctest runs pass all 274 examples. Stubtest also passes on Linux 3.14 and 3.15rc3.
  • An independent 672-case option matrix changes from 54 unexpected rejections to zero. Another 77 controls pass in each environment, including Decimal precision, NaN policy, small stream chunks, bytes/bytearray inputs and callback exception identity. The Windows controls also pass under Python -O.
  • Three isolated mutations pass all 931 original tests but fail 19, 19 and 18 new cases. The source and installed package are restored and the full Linux 3.13 checks pass afterwards.

Risk and unverified checks

This changes accepted syntax only in the two corrected dispatch selections. Numeric representation and NaN rejection are covered by the regression and additional controls.

The Linux 3.14 doctest run fails the native-mode large-integer example at docs/loads.rst:114; a separate immutable-base build reproduces the identical final-digit difference. Debug builds, stable Python 3.15, Python 3.10 doctests/stubtest, Python 3.15rc3 doctests, macOS, other wheel architectures, hosted CI, sanitiser runs, benchmarks and scanner parser coverage are unverified. The stale Python 3.9 tox environments were not run; the repository has no configured lint command.

@lelit

lelit commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for the report and fix! I will try to dedicate some time to RJ next week.

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.

2 participants