Skip to content

Remove ajv-formats-draft2019#1411

Open
pasieronen wants to merge 2 commits intoCycloneDX:mainfrom
pasieronen:replace-ajv-formats-draft2019
Open

Remove ajv-formats-draft2019#1411
pasieronen wants to merge 2 commits intoCycloneDX:mainfrom
pasieronen:replace-ajv-formats-draft2019

Conversation

@pasieronen
Copy link
Copy Markdown

Description

Replace unmaintained dependency ajv-formats-draft2019 with our own implementation.
Continues work started by grease-work-23 in #1226. See also discussion in #1223 and
CycloneDX/cyclonedx-webpack-plugin#1348

The only piece we still used from ajv-formats-draft2019 is "idn-email". I tried to keep the code simple, and re-use ajv-formats (which we anyway depend on) as much as possible.

It might be possible to implement "iri-reference" in similar way (convert to URI, and use "uri-reference" from ajv-fomats), but I'm not sure how useful that would be: almost any string is a valid "uri-reference", so it wouldn't probably catch any problems anyway.

Resolves or fixes issue: #1226

AI Tool Disclosure

  • My contribution does not include any AI-generated content

Affirmation

…or idn-email format (leveraging ajv-formats)

Signed-off-by: Pasi Eronen <pe@iki.fi>
@pasieronen pasieronen requested a review from a team as a code owner April 2, 2026 10:18
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 2, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community bot commented Apr 2, 2026

Documentation build overview

📚 CycloneDX JavaScript Library | 🛠️ Build #32155311 | 📁 Comparing 6f127bd against latest (59c7c7f)

  🔍 Preview build  

Show files changed (1 files in total): 📝 1 modified | ➕ 0 added | ➖ 0 deleted
File Status
install.html 📝 modified

Copy link
Copy Markdown
Member

@jkowalleck jkowalleck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for taking care of this topic.

see my remarks below

ajv.addFormat('iri-reference', true)

// add idn-email format (was previously provided by ajv-formats-draft2019)
const emailValidator = ajv.compile({type: 'string', format: 'email'})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since using our own implementations, we critically need tests for this!
please add test cases:

  • positive cases - like "this is expected to be treated as a valid 'idn-email'"
  • negative cases - like "this is expected to be treated as an invalid 'idn-email'"
  • edge cases - like UTF8 characters, quoted emails ("foo@bar"@baz) and waht not in the

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anything containing only ASCII characters, we just reuse the implementation from ajv-formats (whose definition of what exactly is a valid email might not be identical to somebody else's definition - I don't think we want to write detailed tests for that).

But I agree we need something here to show the code works. I took the test cases I found in https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/e82bfdfa59c63cc74175d35fac81bb95e61db24b/tests/draft2019-09/optional/format/email.json and https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/e82bfdfa59c63cc74175d35fac81bb95e61db24b/tests/draft2019-09/optional/format/idn-email.json,
would those be enough?

Copy link
Copy Markdown
Member

@jkowalleck jkowalleck Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also add edge cases?
Things i can imagine:

  • empty email address (empty string) - shall be a negative
  • to be continued

here are other cases that might be woven in:

see also the test cases of the already used library for reference:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Especially the empty string is a good idea, added couple more at the same time (amended the same commit).

I also noticed that not even ajv-formats and ajv-formats-draft2019 agree on every input. For example, "John Doe"@example.com is valid according to the latter but not the former. That said, I don't expect this to be a problem (and we probably don't want too many tests for rare edge cases, since ajv-formats itself may also change over time).

Signed-off-by: Pasi Eronen <pe@iki.fi>
@pasieronen pasieronen force-pushed the replace-ajv-formats-draft2019 branch from 3779054 to 6f127bd Compare April 7, 2026 17:48
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.

2 participants