Skip to content

Commit

Permalink
Handle blazegraph special characters corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
NZT48 committed Dec 25, 2023
1 parent a3f1b1d commit ba0dc28
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 0 deletions.
Binary file added images/banner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dkg-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/icons/coinmarketcap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions images/icons/discord.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions images/icons/linkedin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions images/icons/medium.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions images/icons/reddit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions images/icons/telegram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions images/icons/x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions images/icons/youtube.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ka.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions images/knowledge-assets-graph1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions images/knowledge-assets-graph2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions images/knowledge-assets-graph3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions images/knowledge-assets-graph4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/nodes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sdk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import OtTripleStore from '../ot-triple-store.js';
class OtBlazegraph extends OtTripleStore {
async initialize(config, logger) {
await super.initialize(config, logger);
// this regex will match \Uxxxxxxxx but will exclude cases where there is a double slash before U (\\U)
this.unicodeRegex = /(?<!\\)\\U([a-fA-F0-9]{8})/g;

await Promise.all(
Object.keys(this.repositories).map(async (repository) => {
Expand Down Expand Up @@ -47,6 +49,40 @@ class OtBlazegraph extends OtTripleStore {
}
}

hasUnicodeCodePoints(input) {
return this.unicodeRegex.test(input);
}

decodeUnicodeCodePoints(input) {
const decodedString = input.replace(this.unicodeRegex, (match, hex) => {
const codePoint = parseInt(hex, 16);
return String.fromCodePoint(codePoint);
});

return decodedString;
}

async _executeQuery(repository, query, mediaType) {
const result = await this.queryEngine.query(
query,
this.repositories[repository].queryContext,
);
const { data } = await this.queryEngine.resultToString(result, mediaType);

let response = '';

for await (const chunk of data) {
response += chunk;
}

// Handle Blazegraph special characters corruption
if (this.hasUnicodeCodePoints(response)) {
response = this.decodeUnicodeCodePoints(response);
}

return response;
}

async healthCheck(repository) {
try {
const response = await axios.get(
Expand Down

0 comments on commit ba0dc28

Please sign in to comment.