Comments (7)
Hi there and thanks for reaching out.
'विकी मेड मेडिकल इनसाइक्लोपीडिया हिंदी में'.length
reports as 41 which I think is due to the multibyte characters required to write Hindi. I don't think that this is something that should be supported by the AJV core library but given the extensibility of AJV you could write your own keywords to correctly handle this text the way you think it should.
edit: actually it is not about unicode pair characters (which are counted as a single character by AJV, it seems to be related to how multiple characters, particularly accents, are grouped together in Hindi?
For example, look at the result of 'विकी मेड मेडिकल इनसाइक्लोपीडिया हिंदी में'.split('')
(41) ['व', 'ि', 'क', 'ी', ' ', 'म', 'े', 'ड', ' ',
'म', 'े', 'ड', 'ि', 'क', 'ल', ' ', 'इ', 'न', 'स', 'ा',
'इ', 'क', '्', 'ल', 'ो', 'प', 'ी', 'ड', 'ि', 'य',
'ा', ' ', 'ह', 'ि', 'ं', 'द', 'ी', ' ', 'म', 'े', 'ं']
from ajv.
there is unicode
option (deprecated, probably) that determines how length is computed.
from ajv.
https://github.com/ajv-validator/ajv/blob/master/lib/vocabularies/validation/limitLength.ts#L25
from ajv.
it's on by default (it does not use length), and if it's not working correctly, it needs fixing
https://github.com/ajv-validator/ajv/blob/master/lib/runtime/ucs2length.ts
from ajv.
Ok, I will have a look
from ajv.
Hi @kelson42 after discussing with EP we have decided that this is not something that we will be fixing within the core AJV library.
This problem is due to the multi-glyph characters that make up this Devanagari charset and no doubt many other languages. A single character like वि
is actually made up of multiple characters व
and 'ि
(notice the dotted line circle that shows how this character interacts with others). These are called grapheme clusters.
From just inspecting the characters there is no metadata that will tell us which chars are part of a grapheme cluster and should therefore be counted as 1. For this reason we cannot put this logic into AJV as it would require a lot of bespoke code to cover all multi-glyph charsets.
This doesn't stop you from solving this problem yourself using custom keywords, you could even publish the solution for others, but it doesn't belong in the AJV code base.
I will however document this issue and I thank you again for bringing it to our attention.
edit: to add a link to the spec on grapheme clusters
from ajv.
@jasoniangreen @epoberezkin Thank you for considering my issue and for your advices. For the record, here how I have fixed the problem.
from ajv.
Related Issues (20)
- additionalProperties shouldn't affect TypeScript types from JTDDataType HOT 10
- option compile from addKeyword doesn't change on a remove and then add again HOT 1
- OneOf validation issue HOT 1
- Cannot find module 'ajv/dist/compile/codegen' HOT 4
- How can I make a property value depend on the value of another property? HOT 1
- Error using multipleOf with decimals HOT 1
- Using if/then/else fails validation HOT 2
- compileParser does not appear to support properties with type `field?: Record<string, unknown>` via `JTDSchemaType`. HOT 6
- Integers as Discriminators HOT 7
- How can I access `definitions` in schema-store using `$ref`? HOT 1
- DeprecationWarning: The punycode module is deprecated #96 HOT 2
- ajv 8.13.0 upgrade doesn't work with ajv-formats 3.0.1 with TypeScript HOT 4
- compileAsync does not loadSchema a schema that is $ref’d by a oneOf with a discriminator HOT 3
- How to return error when the vlaue of field is '' and set the field as required HOT 2
- ajv.compileParser does not exist on type Ajv HOT 1
- ajv schema with key or id "first" already exists HOT 1
- Referencing errors in complex schemas
- Dynamic Error Message in Keyword Compile or Validate Methods HOT 1
- if/then false positive when if-property is undefined. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ajv.