feat: add uuid, date, date-time, uri format validators#96
feat: add uuid, date, date-time, uri format validators#96nic-6443 merged 4 commits intoapi7:masterfrom
Conversation
Add PCRE regex patterns for uuid, date, date-time, and uri formats to the reg_map table. Also update the error message from "address" to "format" since these new formats are not addresses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded regex-based format validators for Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/jsonschema.lua`:
- Line 593: The current ["uri"] pattern in lib/jsonschema.lua is too permissive
(allows whitespace) and rejects scheme-only URIs like "foo:". Replace the
pattern string for the "uri" key with a hardened regex that forbids whitespace
after the colon but permits an empty-path scheme, for example use
^[a-zA-Z][a-zA-Z0-9+\-.]*:(?:\S.*)?$ in place of the existing
^[a-zA-Z][a-zA-Z0-9+\-.]*:.+$ so the "uri" validator disallows whitespace-only
tails while accepting "scheme:" forms.
In `@spec/extra/format.json`:
- Around line 150-186: The test suite under the "tests" array for date/date-time
currently only checks format and simple numeric bounds; add calendar-edge
negative cases so regex-only validators fail correctly — extend the tests (near
existing entries like "invalid date: day 32" and "invalid date: month 13") to
include non-leap-year Feb 29 (e.g., "2023-02-29"), invalid Feb 30/31 (e.g.,
"2024-02-30", "2024-02-31"), months with 30 days receiving 31 (e.g.,
"2024-04-31", "2024-06-31", "2024-09-31", "2024-11-31"), and any invalid
date-time timestamps (e.g., "2024-02-29T12:00:00Z" for non-leap year) so that
the test descriptions and data fields (the entries in the "tests" array) assert
valid: false for these calendar-edge cases.
- Around line 242-283: Add two boundary tests to the existing "tests" array: one
checking that URIs containing whitespace are rejected (e.g., a test object with
"description": "invalid URI: contains whitespace", "data": "http://exa
mple.com", "valid": false) and one checking the empty-path case with a scheme
and colon (e.g., "description": "valid URI: empty path (foo:)", "data": "foo:",
"valid": true); place these new objects alongside the other test entries so the
suite exercises both whitespace handling and the scheme-with-empty-path case.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a0e1c7f1-4d52-4a55-ad98-0cce286dbd05
📒 Files selected for processing (2)
lib/jsonschema.luaspec/extra/format.json
Reject whitespace in URIs by using [^\s]* instead of .+, and accept empty-path URIs like "foo:". Add test cases for these edge cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- ubuntu-18.04 runners are no longer available on GitHub Actions - Update checkout to v4, lua action to v10 - Use gpg keyring instead of deprecated apt-key - Add libpcre3-dev dependency Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/ci.yml:
- Line 32: The CI step that runs "sudo apt-get install -y build-essential
libncurses5-dev libreadline-dev libssl-dev perl libpcre3-dev" should be preceded
by an index refresh; update the run command so it calls "sudo apt-get update"
(or "apt-get update" with sudo) before the first apt-get install invocation in
that step to ensure package lists are current and avoid intermittent CI
failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 235243d2-4629-464e-ba98-9a8d93e19832
📒 Files selected for processing (3)
.github/workflows/ci.ymllib/jsonschema.luaspec/extra/format.json
✅ Files skipped from review due to trivial changes (1)
- spec/extra/format.json
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/jsonschema.lua
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add PCRE regex patterns for
uuid,date,date-time, anduriformats to thereg_maptable, enabling format validation for these commonly used JSON Schema formats.Changes:
lib/jsonschema.lua: added 4 new format regex entries toreg_map, updated error message from "address" to "format"spec/extra/format.json: added test cases for each new format (valid/invalid/non-string inputs, plus URI edge cases for whitespace and empty path).github/workflows/ci.yml: updated runner from ubuntu-18.04 to ubuntu-22.04, modernized actions and GPG key handlingAll existing tests pass locally.
Summary by CodeRabbit
New Features
Tests
Chores