Skip to content

Comments

Fix semver:eq#3 ignoring $coerce parameter#66

Open
joewiz wants to merge 2 commits intoeXist-db:masterfrom
joewiz:fix-eq-coerce
Open

Fix semver:eq#3 ignoring $coerce parameter#66
joewiz wants to merge 2 commits intoeXist-db:masterfrom
joewiz:fix-eq-coerce

Conversation

@joewiz
Copy link
Member

@joewiz joewiz commented Feb 20, 2026

Summary

  • semver:eq#3 was calling semver:compare#2 instead of semver:compare#3, causing the $coerce argument to be silently ignored. Calling semver:eq("1.0", "1.0.0", true()) would throw an error instead of returning true().
  • semver:eq#2 is updated to delegate to semver:eq($v1, $v2, false()), consistent with all other arity-2 comparison functions (lt, le, gt, ge, ne).
  • Two regression tests added to compare.xqm covering the equal and not-equal cases with coercible non-SemVer strings.

Test plan

  • stc:eq-coerce-non-semversemver:eq("1.0", "1.0.0", true()) returns true()
  • stc:eq-coerce-non-semver-not-equalsemver:eq("1.0", "2.0.0", true()) returns false()

🤖 Generated with Claude Code

joewiz and others added 2 commits February 20, 2026 11:27
semver:eq/3 was calling semver:compare/2 instead of semver:compare/3,
causing the \$coerce argument to be silently ignored. Also make semver:eq/2
delegate to semver:eq/3 (with false()) for consistency with all other
arity-2 comparison functions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Test that semver:eq/3 correctly uses $coerce when comparing non-SemVer
strings, covering both the equal and not-equal cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@joewiz
Copy link
Member Author

joewiz commented Feb 20, 2026

For the record, here's the log of the session that produced this PR:

https://gist.github.com/joewiz/0d90cae455ca015bac2a8d2a05eb202c

@joewiz joewiz requested a review from a team February 20, 2026 16:58
@joewiz joewiz added the bug Something isn't working label Feb 20, 2026
@joewiz joewiz changed the title [bugfix] Fix semver:eq/3 ignoring $coerce parameter [bugfix] Fix semver:eq#3 ignoring $coerce parameter Feb 20, 2026
@joewiz joewiz changed the title [bugfix] Fix semver:eq#3 ignoring $coerce parameter Fix semver:eq#3 ignoring $coerce parameter Feb 20, 2026
Copy link
Member

@line-o line-o left a comment

Choose a reason for hiding this comment

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

Looking good.
Would it make sense to have the opposite test as well?

declare
    %test:assertFalse
function stc:eq-non-semver-without-coerce-fails() {
    semver:eq("1.0", "1.0.0", false())
};

@line-o line-o requested a review from a team February 20, 2026 17:15
@joewiz
Copy link
Member Author

joewiz commented Feb 20, 2026

@line-o Thanks! The attempt to parse 1.0 without coercion would cause an error to be thrown. We already test the library's ability to detect "incomplete" SemVer strings (and thus throw that error) here: https://github.com/eXist-db/semver.xq/blob/master/src/test/xquery/validate-and-parse.xqm#L106. So I don't think we need an extra test here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants