Skip to content

Commit

Permalink
Fix version detection for prerelease (#217)
Browse files Browse the repository at this point in the history
* test: Add test case for pre-release version detection in detectVersion

* feat: Update version detection regex to support pre-release versions
  • Loading branch information
absoludity authored Feb 17, 2025
1 parent 181ddff commit f9b4a50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ describe('credentialService', () => {
expect(detectVersion(credential)).toBe('0.5.0');
});

it('should detect pre-release version from UNTP context', () => {
const credential = {
type: ['DigitalProductPassport'],
'@context': ['https://test.uncefact.org/vocabulary/untp/dpp/0.6.0-alpha2'],
};

expect(detectVersion(credential)).toBe('0.6.0-alpha2');
});

it('should detect version from custom domain', () => {
const credential = {
type: ['DigitalLivestockPassport'],
Expand Down
2 changes: 1 addition & 1 deletion packages/untp-playground/src/lib/credentialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function detectVersion(credential: Credential, domain?: string): string {

if (!contextUrl) return 'unknown';

const versionMatch = contextUrl.match(/(\d+\.\d+\.\d+)/);
const versionMatch = contextUrl.match(/(\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+)?)/);
return versionMatch ? versionMatch[1] : 'unknown';
}

Expand Down

0 comments on commit f9b4a50

Please sign in to comment.