Unify frontend SHA-256 normalization
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
} from '../web/resolver/node_context_menu.js';
|
||||
import { startSplitterDrag } from '../web/resolver/utils/splitter_drag.js';
|
||||
import { normalizeDownloadCategoryValue } from '../web/resolver/utils/category_utils.js';
|
||||
import { normalizeSha256 } from '../web/resolver/utils/hash_utils.js';
|
||||
import { baseModelAliasMethods } from '../web/resolver/search/base_model_alias_methods.js';
|
||||
import { searchHashMethods } from '../web/resolver/search/search_hash_methods.js';
|
||||
import { missingModelStateMethods } from '../web/resolver/views/missing_model_state_methods.js';
|
||||
@@ -34,6 +35,7 @@ import {
|
||||
} from '../web/resolver/custom_nodes/registry.js';
|
||||
|
||||
void normalizeDownloadCategoryValue;
|
||||
void normalizeSha256;
|
||||
|
||||
const projectRoot = path.resolve(import.meta.dirname, '..');
|
||||
const queueMethodsSource = fs.readFileSync(
|
||||
|
||||
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { searchHashMethods } from '../web/resolver/search/search_hash_methods.js';
|
||||
import { normalizeSha256 } from '../web/resolver/utils/hash_utils.js';
|
||||
|
||||
function createDialog(overrides = {}) {
|
||||
return { ...searchHashMethods, ...overrides };
|
||||
@@ -10,6 +11,14 @@ function createDialog(overrides = {}) {
|
||||
const hashA = 'a'.repeat(64);
|
||||
const hashB = 'b'.repeat(64);
|
||||
|
||||
test('shared SHA-256 normalization preserves the accepted input contract', () => {
|
||||
assert.equal(normalizeSha256(`sha256:${hashA.toUpperCase()}`), hashA);
|
||||
assert.equal(normalizeSha256('SHA256=' + hashB), hashB);
|
||||
assert.equal(normalizeSha256('short'), '');
|
||||
assert.equal(normalizeSha256(hashA + 'x'), '');
|
||||
assert.equal(normalizeSha256(null), '');
|
||||
});
|
||||
|
||||
test('search hash normalization accepts SHA-256 prefixes and rejects invalid values', () => {
|
||||
const dialog = createDialog();
|
||||
assert.equal(dialog.normalizeSearchResultSha256(`sha256:${hashA.toUpperCase()}`), hashA);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { normalizeSha256 } from '../utils/hash_utils.js';
|
||||
|
||||
export const searchHashMethods = {
|
||||
normalizeSearchResultSha256(value = '') {
|
||||
let text = String(value || '').trim();
|
||||
text = text.replace(/^sha256[:=]/i, '').trim().toLowerCase();
|
||||
return /^[a-f0-9]{64}$/.test(text) ? text : '';
|
||||
return normalizeSha256(value);
|
||||
},
|
||||
|
||||
getSearchResultSha256(result = {}) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export function normalizeSha256(value = '') {
|
||||
let text = String(value || '').trim();
|
||||
text = text.replace(/^sha256[:=]/i, '').trim().toLowerCase();
|
||||
return /^[a-f0-9]{64}$/.test(text) ? text : '';
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { normalizeSha256 } from '../utils/hash_utils.js';
|
||||
|
||||
export const modelHashCompareMethods = {
|
||||
normalizeSha256ForCompare(value = '') {
|
||||
let text = String(value || '').trim();
|
||||
text = text.replace(/^sha256[:=]/i, '').trim().toLowerCase();
|
||||
return /^[a-f0-9]{64}$/.test(text) ? text : '';
|
||||
return normalizeSha256(value);
|
||||
},
|
||||
|
||||
formatSha256Short(value = '') {
|
||||
|
||||
Reference in New Issue
Block a user