Skip to content

fix: accept integer-pixel scroll distances containing 0 in the JSON schema - #1343

Merged
lujjjh merged 1 commit into
linearmouse:mainfrom
YuriNachos:YuriNachos/w3-linearmouse-schema
Aug 9, 2026
Merged

lujjjh merged 1 commit into
linearmouse:mainfrom
YuriNachos:YuriNachos/w3-linearmouse-schema

Conversation

@YuriNachos

Copy link
Copy Markdown
Contributor

Summary

The JSON-schema pattern for Scheme.Scrolling.Distance.Pixel rejected valid integer-pixel scroll distances that contain the digit 0 (e.g. 10px, 20px, 100px, 1000px), even though the Swift runtime decoder accepts them. This made the schema stricter than the actual configuration parser, so valid configs failed schema validation / editor checks.

Root Cause

Documentation/Configuration.d.ts declared the Pixel pattern as ^\d[1-9]*(\.\d+)?px. The character class [1-9] excludes 0, so any multi-digit integer containing a 0 fails to match: for 10px, \d consumes 1 and [1-9]* cannot consume the 0, leaving 0px unmatched against the trailing px. The Swift decoder (Distance.swift, pattern ^([\d.]+)(px|)$) accepts these values, so the schema was a stricter-than-runtime typo (intended [0-9]).

Changes

  • Documentation/Configuration.d.ts: Pixel @pattern integer body [1-9] → [0-9] (^\d[0-9]*(\.\d+)?px).
  • Documentation/Configuration.json: regenerated from the type via npm run generate:json-schema (pre-commit hook).

Integer-pixel values (10px, 20px, 100px, 1000px) now validate; previously-matching values (36px, 256px, 3.5px) are unchanged, and non-pixel values are still rejected.

Verification

make configure clean lint test XCODEBUILD_ARGS="CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= DEVELOPMENT_TEAM="
  • swiftformat --lint . clean; swiftlint . clean.
  • ** TEST SUCCEEDED ** — 523 tests, 0 failures.
  • Regex check against the generated schema pattern: 10px/20px/100px/1000px now match (failed before); 36px/256px/3.5px still match; auto/abc/10/-5px/1.2.3px/px rejected.

Comment thread Documentation/Configuration.d.ts Resolved
…chema

The JSON-schema pattern for Scheme.Scrolling.Distance.Pixel used the character
class [1-9], which excludes 0. This made the schema reject valid integer-pixel
scroll distances containing a 0 (10px, 20px, 100px, 1000px) while the Swift
decoder (^([\d.]+)(px|)$ in Distance.swift) accepted them — the schema was
stricter than the parser.

Replace it with ^(?:0|[1-9]\d*)(?:\.\d+)?px$, which keeps the original intent of
rejecting leading zeros (01px, 007px) that the reversed digit classes had lost,
and anchors the end of the value so a trailing suffix (10pxfoo) is rejected as
the Swift decoder already does. Regenerate Configuration.json from the type.

Co-authored-by: Claude <[email protected]>
@YuriNachos
YuriNachos force-pushed the YuriNachos/w3-linearmouse-schema branch from b2b5dd1 to d03f6f4 Compare August 9, 2026 00:56
@YuriNachos

Copy link
Copy Markdown
Contributor Author

Applied your suggestion — you are right on both counts, and it is a better fix than mine. Pushed as d03f6f4 (amended, still one commit), with Configuration.json regenerated from the type.

I checked all three patterns against a corpus before taking it:

value old ^\d[1-9]*(\.\d+)?px mine ^\d[0-9]*(\.\d+)?px yours ^(?:0|[1-9]\d*)(?:\.\d+)?px$ Swift decoder
0px ✅ ✅ ✅ ✅
10px / 100px / 1000px ❌ ✅ ✅ ✅
36px / 256px / 3.5px ✅ ✅ ✅ ✅
01px / 007px ✅ ✅ ❌ ✅
10pxfoo ✅ ✅ ❌ ❌
10 / auto / -5px ❌ ❌ ❌ mixed

Two things my version missed:

  • Leading zeros. 01px and 007px passed both the old pattern and mine. Yours rejects them, which is what the reversed digit classes were evidently reaching for.
  • The missing end anchor. Without $, 10pxfoo matched. The Swift decoder (^([\d.]+)(px|)$ in Distance.swift) rejects it, so anchoring actually moves the schema closer to runtime rather than further away.

One deliberate difference worth flagging: on 01px the schema is now stricter than the decoder, which still accepts it. I read that as intended — the schema documents the canonical form — but say the word if you would rather it mirror the decoder exactly.

@lujjjh
lujjjh merged commit 0b81eca into linearmouse:main Aug 9, 2026
1 check passed
@lujjjh lujjjh added the bug Something isn't working label Aug 9, 2026
@YuriNachos
YuriNachos deleted the YuriNachos/w3-linearmouse-schema branch August 10, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants