Skip to content

Commit

Permalink
Fix proxy for URLs that include ampersands 😳
Browse files Browse the repository at this point in the history
  • Loading branch information
CorySanin committed Jun 5, 2021
1 parent 355ec35 commit 8a29cfe
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion config/example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"port": 8080,
"blacklist": true,
"domainlist": [
"tauntbot.tk",
"taunt.bot",
"musickitten.net",
"sanin.dev"
],
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const btoa = require('btoa');
const useragent = 'p2z';
const cfgfile = './config/config.json';
const LEADINGAMP = new RegExp('(https?://[^\\s]+\\?)&amp;([^<"\\s]+)', 'g');
const MATCHURL = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:;%_\+.~#?&//=]*)/, 'g');
const XMLENCODEDAMP = new RegExp('&amp;', 'g');
const MATCHURL = new RegExp(/https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:;%_\+.~#?&//=]*)/, 'g');
const MATCHHEX = new RegExp('^[0-9a-fA-F]{1,3}$');
const MATCHBIN = new RegExp('^[01]{1,12}$');
const proxy = httpProxy.createProxyServer({
Expand Down Expand Up @@ -98,7 +99,7 @@ function fixUrls(feed) {
*/
function proxifyUrls(feed, host) {
return (config.deepproxy === true) ? feed.replace(MATCHURL, match => {
return `${host}/proxy/file${getFilename(match).ext}?url=${encodeURIComponent(btoa(match))}`;
return `${host}/proxy/file${getFilename(match).ext}?url=${encodeURIComponent(btoa(match.replace(XMLENCODEDAMP, '&')))}`;
}) : feed;
}

Expand Down
95 changes: 48 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "patreon-to-zune",
"version": "1.4.0",
"version": "1.5.0",
"description": "converts Patreon podcast feeds for the Zune desktop software",
"main": "index.js",
"scripts": {
Expand All @@ -19,6 +19,6 @@
"express": "4.17.1",
"express-useragent": "1.0.15",
"http-proxy": "1.18.1",
"phin": "3.5.1"
"phin": "3.6.0"
}
}

0 comments on commit 8a29cfe

Please sign in to comment.