-
Notifications
You must be signed in to change notification settings - Fork 135
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: parse deep link correctly #573
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -609,6 +609,111 @@ test('Test a url ending with a closing parentheses autolinks correctly', () => { | |
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test urls autolinks correctly', () => { | ||
const testCases = [ | ||
{ | ||
testString: 'test@expensify.com https://www.expensify.com', | ||
resultString: '<a href="mailto:test@expensify.com">test@expensify.com</a> <a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'test@expensify.com-https://www.expensify.com', | ||
resultString: '<a href="mailto:test@expensify.com">test@expensify.com</a>-<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'test@expensify.com/https://www.expensify.com', | ||
resultString: '<a href="mailto:test@expensify.com">test@expensify.com</a>/<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'test@expensify.com?https://www.expensify.com', | ||
resultString: '<a href="mailto:test@expensify.com">test@expensify.com</a>?<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'test@expensify.com>https://www.expensify.com', | ||
resultString: '<a href="mailto:test@expensify.com">test@expensify.com</a>><a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'https://staging.new.expensify.com/details/test@expensify.com', | ||
resultString: '<a href="https://staging.new.expensify.com/details/test@expensify.com" target="_blank" rel="noreferrer noopener">https://staging.new.expensify.com/details/test@expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'staging.new.expensify.com/details', | ||
resultString: '<a href="https://staging.new.expensify.com/details" target="_blank" rel="noreferrer noopener">staging.new.expensify.com/details</a>', | ||
}, | ||
{ | ||
testString: 'https://www.expensify.com?name=test&email=test@expensify.com', | ||
resultString: '<a href="https://www.expensify.com?name=test&email=test@expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com?name=test&email=test@expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'https://staging.new.expensify.com/details?login=testing@gmail.com', | ||
resultString: '<a href="https://staging.new.expensify.com/details?login=testing@gmail.com" target="_blank" rel="noreferrer noopener">https://staging.new.expensify.com/details?login=testing@gmail.com</a>', | ||
}, | ||
{ | ||
testString: 'staging.new.expensify.com/details?login=testing@gmail.com', | ||
resultString: '<a href="https://staging.new.expensify.com/details?login=testing@gmail.com" target="_blank" rel="noreferrer noopener">staging.new.expensify.com/details?login=testing@gmail.com</a>', | ||
}, | ||
{ | ||
testString: 'http://necolas.github.io/react-native-web/docs/?path=/docs/components-pressable--disabled', | ||
resultString: '<a href="http://necolas.github.io/react-native-web/docs/?path=/docs/components-pressable--disabled" target="_blank" rel="noreferrer noopener">http://necolas.github.io/react-native-web/docs/?path=/docs/components-pressable--disabled</a>', | ||
}, | ||
{ | ||
testString: '-https://www.expensify.com /https://www.expensify.com @https://www.expensify.com', | ||
resultString: '-<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a> /<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a> @https://www.expensify.com', | ||
}, | ||
{ | ||
testString: 'expensify.com -expensify.com @expensify.com', | ||
resultString: '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener">expensify.com</a> -<a href="https://expensify.com" target="_blank" rel="noreferrer noopener">expensify.com</a> @expensify.com', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a blocker, and it's not specific to this test case, but I'm wondering if we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean. What I was wondering was wether the result string should be This is related to my comment here, but we can keep this as is for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. |
||
}, | ||
{ | ||
testString: 'https//www.expensify.com', | ||
resultString: 'https//<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">www.expensify.com</a>', | ||
}, | ||
{ | ||
testString: '//www.expensify.com?name=test&email=test@expensify.com', | ||
resultString: '//<a href="https://www.expensify.com?name=test&email=test@expensify.com" target="_blank" rel="noreferrer noopener">www.expensify.com?name=test&email=test@expensify.com</a>', | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
}, | ||
{ | ||
testString: '//staging.new.expensify.com/details?login=testing@gmail.com', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a test case for a string that starts with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean that we need the following test case instead of with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this is my old school thinking, but on browsers, a link like This isn't a blocker |
||
resultString: '//<a href="https://staging.new.expensify.com/details?login=testing@gmail.com" target="_blank" rel="noreferrer noopener">staging.new.expensify.com/details?login=testing@gmail.com</a>', | ||
}, | ||
{ | ||
testString: '/details?login=testing@gmail.com', | ||
resultString: '/details?login=<a href="mailto:testing@gmail.com">testing@gmail.com</a>', | ||
}, | ||
{ | ||
testString: '?name=test&email=test@expensify.com', | ||
resultString: '?name=test&email=<a href="mailto:test@expensify.com">test@expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'example.com/https://www.expensify.com', | ||
resultString: '<a href="https://example.com/https://www.expensify.com" target="_blank" rel="noreferrer noopener">example.com/https://www.expensify.com</a>', | ||
}, | ||
{ | ||
testString: 'test@gmail.com staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com', | ||
resultString: '<a href="mailto:test@gmail.com">test@gmail.com</a> <a href="https://staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com" target="_blank" rel="noreferrer noopener">staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com</a>', | ||
}, | ||
{ | ||
testString: 'test@gmail.com //staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com', | ||
resultString: '<a href="mailto:test@gmail.com">test@gmail.com</a> //<a href="https://staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com" target="_blank" rel="noreferrer noopener">staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com</a>', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
{ | ||
testString: 'test@gmail.com-https://staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com', | ||
resultString: '<a href="mailto:test@gmail.com">test@gmail.com</a>-<a href="https://staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com" target="_blank" rel="noreferrer noopener">https://staging.new.expensify.com/details?login=testing@gmail.com&redirectUrl=https://google.com</a>', | ||
}, | ||
{ | ||
testString: 'test@gmail.com/https://example.com/google@email.com?email=asd@email.com', | ||
resultString: '<a href="mailto:test@gmail.com\">test@gmail.com</a>/<a href="https://example.com/google@email.com?email=asd@email.com" target="_blank" rel="noreferrer noopener">https://example.com/google@email.com?email=asd@email.com</a>', | ||
}, | ||
{ | ||
testString: 'test@gmail.com/test@gmail.com/https://example.com/google@email.com?email=asd@email.com', | ||
resultString: '<a href="mailto:test@gmail.com">test@gmail.com</a>/<a href="mailto:test@gmail.com">test@gmail.com</a>/<a href="https://example.com/google@email.com?email=asd@email.com" target="_blank" rel="noreferrer noopener">https://example.com/google@email.com?email=asd@email.com</a>', | ||
}, | ||
]; | ||
|
||
testCases.forEach(testCase => { | ||
expect(parser.replace(testCase.testString)).toBe(testCase.resultString); | ||
}); | ||
}); | ||
|
||
test('Test markdown style email link with various styles', () => { | ||
const testString = 'Go to ~[Expensify](concierge@expensify.com)~ ' | ||
+ '_[Expensify](concierge@expensify.com)_ ' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong, since
&
shouldn't be present in an href, this is only for HTML contentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'ts from old PR, and we have other test cases to write it in html attribute.
I think &: should be present there.
https://stackoverflow.com/questions/3705591/do-i-encode-ampersands-in-a-href
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is out of scope for this PR. All resultString in test cases converts
&
to&
(not only changes from this PR)And this is actually decoded again:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice thanks for sharing that! TIL you can and should html-encode & signs in html attributes