mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Check document ID when parsing pasted references
Summary: Add doc-id attribute to copied HTML columns next to column type. Only use the raw value (rather than the display value) when the parsed doc-id from pasted HTML matches the current document ID, similar to ensuring that the type matches. This only applies to references and reflists. Test Plan: Extended CopyPaste.ts Reviewers: dsagal Reviewed By: dsagal Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D3154
This commit is contained in:
@@ -45,3 +45,32 @@ export function findLinks(text: string): Array<{value: string, isLink: boolean}>
|
||||
// urls will be at odd-number indices
|
||||
return text.split(urlRegex).map((value, i) => ({ value, isLink : (i % 2) === 1}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on https://stackoverflow.com/a/22429679/2482744
|
||||
* -----------------------------------------------------
|
||||
* Calculate a 32 bit FNV-1a hash
|
||||
* Found here: https://gist.github.com/vaiorabbit/5657561
|
||||
* Ref.: http://isthe.com/chongo/tech/comp/fnv/
|
||||
*/
|
||||
export function hashFnv32a(str: string): string {
|
||||
let hval = 0x811c9dc5;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hval ^= str.charCodeAt(i);
|
||||
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
||||
}
|
||||
// Convert to 8 digit hex string
|
||||
return ("0000000" + (hval >>> 0).toString(16)).substr(-8);
|
||||
}
|
||||
|
||||
/**
|
||||
* A poor man's hash for when proper crypto isn't worth it.
|
||||
*/
|
||||
export function simpleStringHash(str: string) {
|
||||
let result = '';
|
||||
// Crudely convert 32 bits to 128 bits to reduce collisions
|
||||
for (let i = 0; i < 4; i++) {
|
||||
result += hashFnv32a(result + str);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user