Skip to content

Commit

Permalink
Improved message escaping (#42)
Browse files Browse the repository at this point in the history
* Make update-message more consistent with send-message (#39)

* Moved escaper code to shared util

Co-authored-by: Krishna Rajendran <[email protected]>
  • Loading branch information
archive and blazzy authored Mar 13, 2022
1 parent fbd8bf0 commit deecc2e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 22 deletions.
49 changes: 37 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,12 @@ module.exports = invoke;
/***/ }),

/***/ 690:
/***/ ((module) => {
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const {
restoreEscapedNewLine,
restoreEscapedTab,
} = __nccwpck_require__(307);

const buildMessage = (channel = "", text = "", optional = {}) => {
const message = {
Expand All @@ -1747,11 +1752,6 @@ const buildMessage = (channel = "", text = "", optional = {}) => {
return message;
};

const restoreEscapedNewLine = (text) =>
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");

const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");

module.exports = buildMessage;


Expand Down Expand Up @@ -1874,19 +1874,31 @@ module.exports = { addReaction };
/***/ }),

/***/ 51:
/***/ ((module) => {
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const {
restoreEscapedNewLine,
restoreEscapedTab,
} = __nccwpck_require__(307);

const buildUpdateMessage = (channelId = "", text = "", ts = "") => {
const buildMessage = (channel = "", text = "", ts = "", optional = {}) => {
const message = {
channel: channelId,
text: text,
ts: ts,
channel,
text,
ts,
};

message.text = restoreEscapedNewLine(message.text);
message.text = restoreEscapedTab(message.text);

Object.keys(optional).forEach((name) => {
message[name] = optional[name];
});

return message;
};

module.exports = buildUpdateMessage;
module.exports = buildMessage;


/***/ }),
Expand Down Expand Up @@ -1924,6 +1936,19 @@ const updateMessage = async () => {
module.exports = { updateMessage };


/***/ }),

/***/ 307:
/***/ ((module) => {

const restoreEscapedNewLine = (text) =>
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");

const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");

module.exports = { restoreEscapedNewLine, restoreEscapedTab };


/***/ }),

/***/ 491:
Expand Down
10 changes: 5 additions & 5 deletions src/message/build-message.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const {
restoreEscapedNewLine,
restoreEscapedTab,
} = require("../util/escaper.js");

const buildMessage = (channel = "", text = "", optional = {}) => {
const message = {
channel,
Expand All @@ -14,9 +19,4 @@ const buildMessage = (channel = "", text = "", optional = {}) => {
return message;
};

const restoreEscapedNewLine = (text) =>
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");

const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");

module.exports = buildMessage;
22 changes: 17 additions & 5 deletions src/update-message/build-update-message.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
const buildUpdateMessage = (channelId = "", text = "", ts = "") => {
const {
restoreEscapedNewLine,
restoreEscapedTab,
} = require("../util/escaper.js");

const buildMessage = (channel = "", text = "", ts = "", optional = {}) => {
const message = {
channel: channelId,
text: text,
ts: ts,
channel,
text,
ts,
};

message.text = restoreEscapedNewLine(message.text);
message.text = restoreEscapedTab(message.text);

Object.keys(optional).forEach((name) => {
message[name] = optional[name];
});

return message;
};

module.exports = buildUpdateMessage;
module.exports = buildMessage;
6 changes: 6 additions & 0 deletions src/util/escaper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const restoreEscapedNewLine = (text) =>
text.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");

const restoreEscapedTab = (text) => text.replace(/\\t/g, "\t");

module.exports = { restoreEscapedNewLine, restoreEscapedTab };

0 comments on commit deecc2e

Please sign in to comment.