Skip to content

Commit

Permalink
fix to sanitise token JSON, removing control chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Taras authored and Nick Taras committed Nov 27, 2023
1 parent d5cc12b commit 57d088d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions javascript/engine-js/src/view/TokenViewData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TokenScript} from "../TokenScript";
import {Card} from "../tokenScript/Card";
import { TokenScript } from "../TokenScript";
import { Card } from "../tokenScript/Card";

/**
* TokenView data contains helper functions for
Expand All @@ -13,7 +13,7 @@ export class TokenViewData {

}

public async getCurrentTokenData(bypassLocks = false){
public async getCurrentTokenData(bypassLocks = false) {

const attrsData = {};

Expand All @@ -22,7 +22,7 @@ export class TokenViewData {
for (let attr of attrs) {
try {
attrsData[attr.getName()] = await attr.getJsonSafeValue(bypassLocks);
} catch (e){
} catch (e) {
console.warn(e);
}
}
Expand All @@ -39,18 +39,18 @@ export class TokenViewData {

const tokenContextData = await this.tokenScript.getTokenContextData();

return {...attrsData, ...tokenContextData};
return { ...attrsData, ...tokenContextData };
}

public getViewDataId(){
if (!this.viewContainerId){
public getViewDataId() {
if (!this.viewContainerId) {
this.viewContainerId = "token-card-" + this.tokenScript.getCurrentTokenContext()?.selectedTokenId;
}

return this.viewContainerId;
}

public async getTokenJavascript(){
public async getTokenJavascript() {

const tokenData = await this.getCurrentTokenData();

Expand All @@ -61,7 +61,7 @@ export class TokenViewData {

return `
const _currentTokenInstance = JSON.parse('${JSON.stringify(tokenData).replace("^\\'", "\\'")}');
const _currentTokenInstance = JSON.parse('${JSON.stringify(tokenData).replace("^\\'", "\\'").replace(/[\u0000-\u001F]/g, "")}');
const walletAddress = '${tokenData.ownerAddress}'
const addressHex = "${tokenData.ownerAddress}";
Expand Down

0 comments on commit 57d088d

Please sign in to comment.