Skip to content

Commit

Permalink
fix(NxRichText): Match IP addresses as links
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 28, 2023
1 parent d1d7d1b commit 7e965e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/NcRichText/NcRichText.vue
Expand Up @@ -39,6 +39,8 @@ export default {
return {
text: `Hello {username}. The file {file} was added by {username}. Go visit https://nextcloud.com
Local IP: http://127.0.0.1/status.php should be clickable
Some examples for markdown syntax: **bold text** *italic text* ~~strikethrough~~`,
autolink: true,
useMarkdown: true,
Expand Down
4 changes: 2 additions & 2 deletions src/components/NcRichText/helpers.js
@@ -1,4 +1,4 @@
export const URL_PATTERN = /(\s|^)(https?:\/\/)((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig
export const URL_PATTERN = /(\s|^)(https?:\/\/)((?:[-A-Z0-9+_]+\.)+[-A-Z0-9]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig

// FIXME See if we can merge those two
export const URL_PATTERN_AUTOLINK = /(\s|\(|^)((https?:\/\/)((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*))(?=\s|\)|$)/ig
export const URL_PATTERN_AUTOLINK = /(\s|\(|^)((https?:\/\/)((?:[-A-Z0-9+_]+\.)+[-A-Z0-9]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*))(?=\s|\)|$)/ig
11 changes: 11 additions & 0 deletions tests/unit/components/NcRichText/NcRichText.spec.js
Expand Up @@ -152,6 +152,17 @@ describe('Foo', () => {
expect(wrapper.find('a').attributes('href')).toEqual('https://example.com:444')
})

it('properly recognizes an url with an IP address and inserts a link', async() => {
const wrapper = mount(NcRichText, {
propsData: {
text: 'Testwith a link to https://127.0.0.1/status.php - go visit it',
autolink: true
}
})
expect(wrapper.text()).toEqual('Testwith a link to https://127.0.0.1/status.php - go visit it')
expect(wrapper.find('a').attributes('href')).toEqual('https://127.0.0.1/status.php')
})

it('properly formats markdown', async() => {
const wrapper = mount(NcRichText, {
propsData: {
Expand Down

0 comments on commit 7e965e5

Please sign in to comment.