Skip to content

[json_syntax_generator] Pub format semver regexp fix - #3293

Merged
dcharkes merged 2 commits into
mainfrom
pub-format-fix
Apr 8, 2026
Merged

dcharkes merged 2 commits into
mainfrom
pub-format-fix

Conversation

@lrhn

@lrhn lrhn commented Apr 7, 2026

Copy link
Copy Markdown
Member

Fixes dart-lang/sdk#63110

The RegExp used to validate the package version in pubspec.yaml allows a build-identifier (+....),
the one for pubspec.lock does not.

This adds a (?:\+...)? part to the pubspec.lock format. Also adds - to the valid characters in pre-release and build identifier.

(@dcharkes What is the goal of these version RegExps?
This fix should make them accept all valid SemVer versions, as well as some invalid versions. That's still an improvement on having both false positives and negatives - aka, an "extended subset".

If the goal is to have no false negatives, this PR should do that (I think!). That's a good goal, it means we won't complain on valid user-written versions.

If the goal is to have no false positives, I can build a RegExp for that. It'll be bigger, but it's possible.

If we want to allow false positives ... why do we allow some false positives, but not all? There a RegExp here, instead of just a String type, like there is for environment: sdk: "any string here". If we pass the version string to a SemVer parser later, then we'll catch the false positives there.)

lrhn added 2 commits April 7, 2026 15:30
Also add `-` to the allowed characters in pre-release and build
identifiers.

The RegExp over-matches (accepts some strings that are not valid
SemVer versions), but now shouldn't reject any valid SemVer
version strings.
@lrhn
lrhn requested a review from dcharkes April 7, 2026 16:31
@github-actions

github-actions Bot commented Apr 7, 2026 •

Copy link
Copy Markdown

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

@dcharkes dcharkes changed the title Pub format semver regexp fix [json_syntax_generator] Pub format semver regexp fix Apr 7, 2026
@dcharkes

dcharkes commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator

This fix should make them accept all valid SemVer versions, as well as some invalid versions. That's still an improvement on having both false positives and negatives - aka, an "extended subset".

Yes, that's an improvement! 🙏

No, we want no false negatives because we're reading random pubspecs and locks.

(False positives is fine, the syntax classes cannot catch semantic errors, so there's always a second layer of validation. But things that are syntax errors are nicer if they are syntax errors. It means that semantic error checking doesn't need to have fallbacks for syntactic errors. But we don't have a semantic layer around the syntactic layer in this package. Unlike some of the other syntax definitions in this repo.)

const _validBuildParts = [
..._validPreReleaseParts,
// Also allows a leading zero, `0<digits>`.
'007',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🔫 🕵️

@dcharkes dcharkes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @lrhn 🙏

@dcharkes
dcharkes merged commit 3300d22 into main Apr 8, 2026
31 of 33 checks passed
@dcharkes
dcharkes deleted the pub-format-fix branch April 8, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dart installed throws FormatException exception when a package version contains a build number

2 participants