Skip to content

Commit

Permalink
Merge pull request #76 from xJeneKx/master
Browse files Browse the repository at this point in the history
escape title
  • Loading branch information
tonyofbyteball committed Sep 23, 2022
2 parents e3c8f16 + 6807088 commit bfa81a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v10.24.1
v16.16.0
11 changes: 10 additions & 1 deletion explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var conf = require('ocore/conf.js');
var eventBus = require('ocore/event_bus.js');
var network = require('ocore/network.js');
const device = require('ocore/device');
const { isValidAddress } = require('ocore/validation_utils.js');
const express = require("express");
const cors = require('cors')
const { createServer } = require("http");
Expand All @@ -23,6 +24,7 @@ const app = express();
const httpServer = createServer(app);

const checkIsUnitValid = require('./helpers/isValidUnit');
const escape = require('./helpers/escape');
const { checkAndChangeAssetName } = require('./helpers/checkAndChangeAssetName');

const api = require('./gateways/api');
Expand Down Expand Up @@ -80,6 +82,9 @@ watchFile(pathToIndex, async () => {
function indexHandler(req, res) {
let title = '';
if (req.params.unit) {
if (!checkIsUnitValid(req.params.unit)) {
return res.redirect('/');
}
title = `Unit ${req.params.unit} details on Obyte DAG chain | `
}
title += desc;
Expand All @@ -89,6 +94,10 @@ function indexHandler(req, res) {
}

function addressHandler(req, res) {
if (!req.params.address || !isValidAddress(req.params.address)) {
return res.redirect('/');
}

let title = `Address ${req.params.address} transactions and portfolio | ` + desc;

const html = indexFile.replaceAll('{og_text}', title);
Expand All @@ -104,7 +113,7 @@ async function assetHandler(req, res) {
}
}
asset = checkAndChangeAssetName(asset);
let title = `Token ${asset} transactions and holders | ` + desc;
let title = `Token ${escape(asset)} transactions and holders | ` + desc;

const html = indexFile.replaceAll('{og_text}', title);
res.send(html);
Expand Down
10 changes: 10 additions & 0 deletions helpers/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function escape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}

module.exports = escape;

0 comments on commit bfa81a7

Please sign in to comment.