Skip to content

Commit deecc2e

Browse files
archiveblazzy
andauthored
Improved message escaping (#42)
* Make update-message more consistent with send-message (#39) * Moved escaper code to shared util Co-authored-by: Krishna Rajendran <krishna@emptybox.org>
1 parent fbd8bf0 commit deecc2e

File tree

4 files changed

+65
-22
lines changed

4 files changed

+65
-22
lines changed

dist/index.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,12 @@ module.exports = invoke;
17291729
/***/ }),
17301730

17311731
/***/ 690:
1732-
/***/ ((module) => {
1732+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1733+
1734+
const {
1735+
restoreEscapedNewLine,
1736+
restoreEscapedTab,
1737+
} = __nccwpck_require__(307);
17331738

17341739
const buildMessage = (channel = "", text = "", optional = {}) => {
17351740
const message = {
@@ -1747,11 +1752,6 @@ const buildMessage = (channel = "", text = "", optional = {}) => {
17471752
return message;
17481753
};
17491754

1750-
const restoreEscapedNewLine = (text) =>
1751-
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");
1752-
1753-
const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");
1754-
17551755
module.exports = buildMessage;
17561756

17571757

@@ -1874,19 +1874,31 @@ module.exports = { addReaction };
18741874
/***/ }),
18751875

18761876
/***/ 51:
1877-
/***/ ((module) => {
1877+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1878+
1879+
const {
1880+
restoreEscapedNewLine,
1881+
restoreEscapedTab,
1882+
} = __nccwpck_require__(307);
18781883

1879-
const buildUpdateMessage = (channelId = "", text = "", ts = "") => {
1884+
const buildMessage = (channel = "", text = "", ts = "", optional = {}) => {
18801885
const message = {
1881-
channel: channelId,
1882-
text: text,
1883-
ts: ts,
1886+
channel,
1887+
text,
1888+
ts,
18841889
};
18851890

1891+
message.text = restoreEscapedNewLine(message.text);
1892+
message.text = restoreEscapedTab(message.text);
1893+
1894+
Object.keys(optional).forEach((name) => {
1895+
message[name] = optional[name];
1896+
});
1897+
18861898
return message;
18871899
};
18881900

1889-
module.exports = buildUpdateMessage;
1901+
module.exports = buildMessage;
18901902

18911903

18921904
/***/ }),
@@ -1924,6 +1936,19 @@ const updateMessage = async () => {
19241936
module.exports = { updateMessage };
19251937

19261938

1939+
/***/ }),
1940+
1941+
/***/ 307:
1942+
/***/ ((module) => {
1943+
1944+
const restoreEscapedNewLine = (text) =>
1945+
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");
1946+
1947+
const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");
1948+
1949+
module.exports = { restoreEscapedNewLine, restoreEscapedTab };
1950+
1951+
19271952
/***/ }),
19281953

19291954
/***/ 491:

src/message/build-message.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
const {
2+
restoreEscapedNewLine,
3+
restoreEscapedTab,
4+
} = require("../util/escaper.js");
5+
16
const buildMessage = (channel = "", text = "", optional = {}) => {
27
const message = {
38
channel,
@@ -14,9 +19,4 @@ const buildMessage = (channel = "", text = "", optional = {}) => {
1419
return message;
1520
};
1621

17-
const restoreEscapedNewLine = (text) =>
18-
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");
19-
20-
const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");
21-
2222
module.exports = buildMessage;
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
const buildUpdateMessage = (channelId = "", text = "", ts = "") => {
1+
const {
2+
restoreEscapedNewLine,
3+
restoreEscapedTab,
4+
} = require("../util/escaper.js");
5+
6+
const buildMessage = (channel = "", text = "", ts = "", optional = {}) => {
27
const message = {
3-
channel: channelId,
4-
text: text,
5-
ts: ts,
8+
channel,
9+
text,
10+
ts,
611
};
712

13+
message.text = restoreEscapedNewLine(message.text);
14+
message.text = restoreEscapedTab(message.text);
15+
16+
Object.keys(optional).forEach((name) => {
17+
message[name] = optional[name];
18+
});
19+
820
return message;
921
};
1022

11-
module.exports = buildUpdateMessage;
23+
module.exports = buildMessage;

src/util/escaper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const restoreEscapedNewLine = (text) =>
2+
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");
3+
4+
const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");
5+
6+
module.exports = { restoreEscapedNewLine, restoreEscapedTab };

0 commit comments

Comments
 (0)