Disallow links without protocol (e.g. starting with http(s)://) in LinkedText. (#32972)
* Disallow links without protocols in LinkedText. * Update tests
This commit is contained in:
@@ -49,6 +49,15 @@ describe("LinkedText", () => {
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("does not linkify domains without a protocol.", () => {
|
||||
const { queryAllByRole } = render(
|
||||
<LinkedTextContext value={{}}>
|
||||
<LinkedText>Check out this link github.com</LinkedText>
|
||||
</LinkedTextContext>,
|
||||
);
|
||||
expect(queryAllByRole("link")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("renders a user ID", () => {
|
||||
const { container } = render(<WithUserId />);
|
||||
expect(container).toMatchSnapshot();
|
||||
@@ -73,7 +82,7 @@ describe("LinkedText", () => {
|
||||
const fn = vitest.fn();
|
||||
const { getAllByRole } = render(
|
||||
<LinkedTextContext value={{}}>
|
||||
<LinkedText onLinkClick={fn}>Check out this link https://google.com and example.org</LinkedText>
|
||||
<LinkedText onLinkClick={fn}>Check out this link https://google.com and https://example.org</LinkedText>
|
||||
</LinkedTextContext>,
|
||||
);
|
||||
const links = getAllByRole("link");
|
||||
|
||||
@@ -228,10 +228,10 @@ export function generateLinkedTextOptions({
|
||||
: undefined),
|
||||
// By default, ignore Matrix ID types.
|
||||
// Other applications may implement their own version of LinkifyComponent.
|
||||
validate: (_value, type: string) =>
|
||||
validate: (value, type: string) =>
|
||||
!!(type === LinkifyMatrixOpaqueIdType.UserId && userIdListener) ||
|
||||
!!(type === LinkifyMatrixOpaqueIdType.RoomAlias && roomAliasListener) ||
|
||||
type === LinkifyMatrixOpaqueIdType.URL,
|
||||
!!(type === LinkifyMatrixOpaqueIdType.URL && URL.canParse(value)),
|
||||
} satisfies linkifyjs.Opts;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user