Locale dependent error in addRangeCheck() function
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start at lib/jsonschema.lua around line 577 and inspect addRangeCheck(...), especially how string.format renders numeric range limits. Verify the generated validator under a locale that uses a comma decimal separator, then confirm the generated Lua remains valid and numeric range checks still work.
Written by the indexing model from the issue text.
Description
The generate validator function generates lua code as string object which is then used to validate JSON data.
If the given JSON schema contains a numeric value with range limitation, the function addRangeCheck(...) is called.
As this function uses string.format to generate if statements, the range limit which is given as type number will convert the number to a string. Depending on he active locale, the number is represented with either a comma or a full stop as a decimal separator. If a comma is used as decimal separator, the generated lua code is invalid.
A possible fix would be to set a different locale temporarily to make sure a full stop is used as decimal separator, e.g.:
local function addRangeCheck(ctx, op, reference, msg)
active_locale = os.setlocale(nil)
os.setlocale("C")
ctx:stmt(sformat(' if %s %s %s then', ctx:param(1), op, reference))
ctx:stmt(sformat(' return false, %s("expected %%s to be %s %s", %s)',
ctx:libfunc('string.format'), msg, reference, ctx:param(1)))
ctx:stmt( ' end')
os.setlocale(active_locale)
end
- Dominant language
- Lua
- Stars
- 136
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from api7/jsonschema
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
api7/jsonschema#105 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
api7/jsonschema#93 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
api7/jsonschema#92 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
api7/jsonschema#91 ·
-
Support pcre2 Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
api7/jsonschema#89 ·
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
api7/lua-resty-saml#62 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
nvim-tree/nvim-tree.lua#3357 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
codymikol/multiverse.nvim#320 ·
-
Data Correction tbc
Difficulty 2/5 1-3 hours Newbie friendliness 68/100