Skip to content

Commit

Permalink
Merge pull request #3580 from OriginTrail/v8/data-migration-improvements
Browse files Browse the repository at this point in the history
Fix regex
  • Loading branch information
Mihajlo-Pavlovic authored Dec 23, 2024
2 parents ff2f756 + 9c24b57 commit 012e81f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions v8-data-migration/triple-store-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,23 @@ export async function queryVoid(tripleStoreRepositories, repository, query) {
}

function hasSpecialCharactersInIRI(assertion) {
// Match only triples' subjects that contain special characters
// eslint-disable-next-line no-useless-escape
const subjectPattern = /^<[^>]*[{}\\\|][^>]*>(?=\s+<)/;
const lines = assertion.split('\n');
return lines.some((line) => subjectPattern.test(line.trim()));
// {, }, |, ^, `, and \ without u or U
// eslint-disable-next-line no-useless-escape
const iriPattern = /<[^>]*(?:[\s{}\|^`]|\\(?![uU]))[^>]*>/;

return lines.some((line) => {
// Split quad into subject, predicate, object (ignore graph if present)
const parts = line.trim().split(' ');

// Check each part only if it starts with < and ends with >
return parts.some((part) => {
if (part.startsWith('<') && part.endsWith('>')) {
return iriPattern.test(part);
}
return false;
});
});
}

export async function insertAssertionsIntoV8UnifiedRepository(
Expand All @@ -586,7 +598,8 @@ export async function insertAssertionsIntoV8UnifiedRepository(

if (hasSpecialCharactersInIRI(publicAssertion)) {
logger.warn(
`Public assertion with tokenId: ${tokenId} contains illegal characters in IRI. Skipping...`,
`Public assertion with tokenId: ${tokenId} contains illegal characters in IRI. Skipping...
Public assertion: ${publicAssertion}`,
);
successfullyProcessed.push(tokenId);
continue;
Expand Down

0 comments on commit 012e81f

Please sign in to comment.