Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Util): escapeInlineCode properly #7587

Merged
merged 2 commits into from
Mar 6, 2022
Merged

fix(Util): escapeInlineCode properly #7587

merged 2 commits into from
Mar 6, 2022

Conversation

imranbarbhuiya
Copy link
Contributor

Please describe the changes this PR makes and why it should be merged:
fixes: #7373

The purpose of this method is to remove all the markdowns but as shown in the issue that it's not able to remove inlineCode for some strings where additional backticks are used. The current change works fine for any input.
Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

fixes: #7373

The purpose of this method is to remove all the markdowns but as shown in the issue that it's not able to remove `inlineCode` for some strings where additional backtics are used. The current change works fine for any input.
@iCrawl iCrawl added this to the discord.js v14 milestone Mar 4, 2022
@iCrawl iCrawl merged commit 851f380 into discordjs:main Mar 6, 2022
@imranbarbhuiya imranbarbhuiya deleted the patch-1 branch March 6, 2022 16:20
@dshepsis
Copy link

dshepsis commented Mar 6, 2022

I don't this patch is correct. This simply escapes all backticks. As a result, it does escape inline code, but also escapes code blocks, even though that's a separate function and not the intended functionality of this function by itself. A fix should be implemented, and tests should be added, to ensure that this function does not escape backticks which form a code block in discord. I've tried a few different strings, and I'm not sure exactly what the correct rules are. For example:

This one:

```a`

Results in inline code containing "``a".

This one:

`a```b```

Results in plaintext "`a" followed by a code block containing "b"

And this one:

`a\```b```

Results in plaintext "`a```b```"

There are probably more weird corner cases like this. Not really sure what the best solution is, other than to randomly generate a bunch of these, and then progressively add more of them as test cases until there are no discrepancies between what Discord and Discord.js identify as inline code or a code block.

@imranbarbhuiya
Copy link
Contributor Author

I don't this patch is correct. This simply escapes all backticks. As a result, it does escape inline code, but also escapes code blocks, even though that's a separate function and not the intended functionality of this function by itself. A fix should be implemented, and tests should be added, to ensure that this function does not escape backticks which form a code block in discord. I've tried a few different strings, and I'm not sure exactly what the correct rules are. For example:

This one:

```a`

Results in inline code containing "``a".

This one:

`a```b```

Results in plaintext "`a" followed by a code block containing "b"

And this one:

`a\```b```

Results in plaintext "`ab"

There are probably more weird corner cases like this. Not really sure what the best solution is, other than to randomly generate a bunch of these, and then progressively add more of them as test cases until there are no discrepancies between what Discord and Discord.js identify as inline code or a code block.

I'll probably create a new pr to ignore code blocks.

@monbrey
Copy link
Member

monbrey commented Mar 6, 2022

Why would it be a new PR if it's been identified as a defect of this PR?

EDIT: I see now this is already merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Util.escapeInlineCode fails to properly escape inline code in some cases
5 participants