Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements for feature macros #195

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

dominickpastore
Copy link

This PR does two things:

  • Create more granular macros for specific non-strict features
  • Enable strict mode and parent links by default

Details

More granular macros

This PR builds on the changes from PR #194. With PR #194, there are three specific ways in which non-strict mode diverges from RFC 8259:

  1. Primitives may contain any character except whitespace and those with special meaning in JSON ({}[],:").
  2. Strings may contain control characters (\x01 - \x1F) and invalid escape sequences
  3. Primitives may be used as object keys

Some projects using jsmn might want some of these features, but not all. For example, a project might want to enable (1) to improve performance or shrink code size, but leave (3) disabled to help catch bugs.

For this purpose, this PR creates three new macros: JSMN_PERMISSIVE_PRIMITIVES for (1), JSMN_PERMISSIVE_STRINGS for (2), and JSMN_PRIMITIVE_KEYS for (3). These can be defined individually, or defining JSMN_NON_STRICT will cause all to be defined.

Enable strict mode and parent links by default

With this PR, strict RFC 8259 compliance and parent links become the default behavior. New macros JSMN_LOW_MEMORY and JSMN_NON_STRICT disable these behaviors.

JSMN_PARENT_LINKS still exists, but is defined by default unless JSMN_LOW_MEMORY is defined.

JSMN_NON_STRICT replaces JSMN_STRICT. When defined, all non-strict features are enabled.

Ensure primitives are "true", "false", "null", or an RFC 8259 compliant
number. (Still need to add test cases.)
String parsing previously did not differ between strict and non-strict
modes, but was not fully compliant with RFC 8259. RFC 8259 requires that
control characters (code points < 0x20) be escaped. This is now enforced
in strict mode. In addition, non-strict mode now does *no* validations
on string contents, much like primitives in non-strict mode.
@dominickpastore
Copy link
Author

Apologize for the history rewriting. Rebased onto the latest commits from PR #194.

Parent links and strict parsing are now the default behavior. New macros
JSMN_LOW_MEMORY and JSMN_NON_STRICT disable these behaviors.

JSMN_PARENT_LINKS still exists, but is defined by default unless
JSMN_LOW_MEMORY is defined.

JSMN_STRICT no longer exists. Instead, we have three new macros:

JSMN_PERMISSIVE_PRIMITIVES - Relaxes validation of primitives. Any
characters except whitespace and {}[],:" become allowed. (Normally, only
"true", "false", "null", and RFC 8259 numbers are permitted.)

JSMN_PERMISSIVE_STRINGS - Relaxes validation of strings. Any characters
allowed. (Normally, control characters (<0x20) and invalid escape
sequences are foridden.)

JSMN_PRIMITIVE_KEYS - Allows primitives to be used as object keys.

These can be defined individually, or defining JSMN_NON_STRICT will
cause all to be defined.

Tests have not yet been adapted for these changes.
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