Fix: avoid to generate the same key for two different imported svg (#824)

* Fix: avoid to generate the same key for two different imported svg
* fix linter issues

Co-authored-by: Cédric Godefroy <cedric.godefroy@flexybeauty.com>
Co-authored-by: JFH <20402845+jfhenon@users.noreply.github.com>
master
cg-scorpio 2022-07-27 09:55:47 +02:00 committed by GitHub
parent 6eb5224213
commit b1a0b6de43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -17,11 +17,11 @@ import {
preventClickDefault,
toXml,
getStrokedBBoxDefaultVisible,
encode64,
createObjectURL,
dataURLToObjectURL,
walkTree,
getBBox as utilsGetBBox
getBBox as utilsGetBBox,
hashCode
} from './utilities.js'
import { transformPoint, transformListToTransform } from './math.js'
import { convertUnit, shortFloat, convertToNum } from '../common/units.js'
@ -633,7 +633,7 @@ const importSvgString = (xmlString) => {
let useEl
try {
// Get unique ID
const uid = encode64(xmlString.length + xmlString).substr(0, 32)
const uid = hashCode(xmlString)
let useExisting = false
// Look for symbol and make sure symbol exists in image

View File

@ -144,6 +144,23 @@ export function decode64 (input) {
return decodeUTF8(window.atob(input))
}
/**
* Compute a hashcode from a given string
* @param word : the string, we want to compute the hashcode
* @returns {number}: Hascode of the given string
*/
export function hashCode (word) {
let hash = 0
let chr
if (word.length === 0) return hash
for (let i = 0; i < word.length; i++) {
chr = word.charCodeAt(i)
hash = ((hash << 5) - hash) + chr
hash |= 0 // Convert to 32bit integer
}
return hash
}
/**
* @function module:utilities.decodeUTF8
* @param {string} argString