Skip to content

Commit 9ed4a17

Browse files
committed
Unescape Lua strings
1 parent 5c8091f commit 9ed4a17

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/_data/depctrl.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,27 @@ const checkFileIntegrity = async (feeds) => {
4545
return feeds;
4646
}
4747

48+
const unescapeLuaString = (string) => {
49+
// Source https://www.lua.org/pil/2.4.html
50+
string = string.replaceAll("\\a", ""); // bell
51+
string = string.replaceAll("\\b", "\b"); // back space
52+
string = string.replaceAll("\\f", "\f"); // form feed
53+
string = string.replaceAll("\\n", "\n"); // newline
54+
string = string.replaceAll("\\r", "\r"); // carriage return
55+
string = string.replaceAll("\\t", "\t"); // horizontal tab
56+
string = string.replaceAll("\\v", "\v"); // vertical tab
57+
string = string.replaceAll("\\\"", "\""); // double quote
58+
string = string.replaceAll("\\'", "'"); // single quote
59+
string = string.replaceAll("\\[", "["); // left square bracket
60+
string = string.replaceAll("\\]", "]"); // right square bracket
61+
string = string.replaceAll("\\\\", "\\"); // backslash
62+
return string
63+
}
64+
4865
const extractProperty = (script, property) => {
4966
var match = Array.from(script.matchAll(new RegExp(`\\s*${property}\\s*=\\s*(?:tr)?(?:"([^"]*)"|'([^']*)')`, 'g')));
5067
if (match.length === 1) {
51-
return (match[0][1] || "") + (match[0][2] || "");
68+
return unescapeLuaString((match[0][1] || "") + (match[0][2] || ""));
5269
}
5370
return null;
5471
}
@@ -59,7 +76,7 @@ const extractFeedData = (script) => {
5976
feedData = match[0][1];
6077
var feed = Array.from(feedData.matchAll(/^[^{]*feed\s*[:=]\s*["']([^"']+)["']/g));
6178
if (feed.length === 1) {
62-
return {feed: feed[0][1]}
79+
return { feed: feed[0][1] }
6380
}
6481
}
6582
return null;

0 commit comments

Comments
 (0)