From 886d2c0a1cd7b07d6ecc787dc020b4126801c046 Mon Sep 17 00:00:00 2001 From: Hugo Costa Date: Wed, 11 May 2022 10:44:17 -0300 Subject: [PATCH] fix(message-parser): Link is not showing correct and it not opening correctly (#717) --- packages/message-parser/src/grammar.pegjs | 15 ++- packages/message-parser/tests/link.test.ts | 142 +++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) diff --git a/packages/message-parser/src/grammar.pegjs b/packages/message-parser/src/grammar.pegjs index b0711e2071..c4393da4b5 100644 --- a/packages/message-parser/src/grammar.pegjs +++ b/packages/message-parser/src/grammar.pegjs @@ -437,6 +437,10 @@ safe / "&" / "=" / "%" + / "!" + / "~" + / "_" + / "+" extra = "!" @@ -509,7 +513,16 @@ phonePrefix * */ -URL = $(s:urlScheme a:urlAuthority p:urlPath? q:urlQuery? f:urlFragment?) +URL + = $( + s:urlScheme + a:urlAuthority + p:urlPath? + q:urlQuery? + f:urlFragment? + g:urlPath? + h:urlQuery? + ) urlScheme = $( diff --git a/packages/message-parser/tests/link.test.ts b/packages/message-parser/tests/link.test.ts index ed7e13286a..17806016eb 100644 --- a/packages/message-parser/tests/link.test.ts +++ b/packages/message-parser/tests/link.test.ts @@ -72,6 +72,148 @@ test.each([ ]), ], ], + [ + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351' + ), + ]), + ], + ], + [ + '', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + plain('Test') + ), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + plain('title') + ), + ]), + ], + ], + [ + '[**title**](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + bold([plain('title')]) + ), + ]), + ], + ], + [ + '[~~title~~](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + strike([plain('title')]) + ), + ]), + ], + ], + [ + '[__title__](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + italic([plain('title')]) + ), + ]), + ], + ], + [ + '[__**~~title~~**__](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + italic([bold([strike([plain('title')])])]) + ), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34', + plain('title') + ), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do?query=test12-34#Cases/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do?query=test12-34#Cases/dv/413244000073043351', + plain('title') + ), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abc123)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abc123', + plain('title') + ), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351', + plain('title') + ), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351', + plain('title') + ), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abcd!~-._%2B+)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abcd!~-._%2B+', + plain('title') + ), + ]), + ], + ], ])('parses %p', (input, output) => { expect(parser(input)).toMatchObject(output); });