Skip to content

Commit

Permalink
Merge pull request #47 from rpiambulance/fix-greater-less-amp
Browse files Browse the repository at this point in the history
Fix &, <, and > replacement
  • Loading branch information
lramos15 authored Feb 2, 2020
2 parents 9372e74 + f9344d1 commit 38f2cbc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@slack/web-api": "^5.2.1",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.17.1",
"@types/node": "^13.7.0",
"@types/qs": "^6.5.3",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
Expand Down
2 changes: 2 additions & 0 deletions src/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class Actions {
public onButtonAction(payload: any, res: (message: any) => Promise<unknown>): { text: string } {
try {
const poll = new Poll(payload.message.blocks);
payload.actions[0].text.text = payload.actions[0].text.text.replace("&lt;","<")
.replace("&gt;",">").replace("&amp;","&");
poll.vote(payload.actions[0].text.text, payload.user.id);
payload.message.blocks = poll.getBlocks();
payload.message.text = "Vote changed!";
Expand Down
7 changes: 3 additions & 4 deletions src/Poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ export class Poll {
actionBlocks.push(newActionBlock);
actionBlockCount++;
}
// Remove special characters, should be able to remove this once slack figures itself out
parameters[i] = parameters[i].replace("&amp;", "+").replace("&gt;", "greater than ")
.replace("&lt;", "less than ");
// We set value to empty string so that it is always defined
const button: Button = { type: "button", value: " ", text: PollHelpers.buildTextElem(parameters[i]) };
actionBlocks[actionBlockCount].elements.push(button);
Expand Down Expand Up @@ -149,6 +146,8 @@ export class Poll {
for (let j = 0; j < currentBlock.elements.length; j++) {
if (currentBlock.elements[j].type !== "button") continue;
const button = currentBlock.elements[j] as Button;
button.text.text = button.text.text.replace("&lt;","<")
.replace("&gt;",">").replace("&amp;","&");
if (buttonCallback(button)) break;
}
}
Expand Down Expand Up @@ -194,4 +193,4 @@ export class Poll {
}
return -1;
}
}
}

0 comments on commit 38f2cbc

Please sign in to comment.