-
-
Notifications
You must be signed in to change notification settings - Fork 13
1.0.6 - Fixed baseUrl events check #58
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { EmbedEvents } from '../types'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
type EventHandler = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
[key in EmbedEvents['event']]?: (data: Extract<EmbedEvents, { event: key }>) => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
[key in EmbedEvents['event']]?: ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
data: Extract<EmbedEvents, { event: key }> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
) => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
export function handleEvent(event: MessageEvent, handlers: EventHandler, baseUrl?: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!event.origin.includes('embed.diagrams.net') && (baseUrl && !event.origin.includes(baseUrl))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
export function handleEvent( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
event: MessageEvent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
handlers: EventHandler, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
baseUrl?: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
!event.origin.includes('embed.diagrams.net') && | ||||||||||||||||||||||||||||||||||||||||||||||||||||
baseUrl && | ||||||||||||||||||||||||||||||||||||||||||||||||||||
!baseUrl.includes(event.origin) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||
!event.origin.includes(baseUrl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+9
to
+19
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. [nitpick] The compound conditional for origin checks is complex—consider extracting it into a descriptive helper function (e.g.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -23,4 +34,4 @@ export function handleEvent(event: MessageEvent, handlers: EventHandler, baseUrl | |||||||||||||||||||||||||||||||||||||||||||||||||||
} catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
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.
Rather than using string
includes
for URL matching, parsebaseUrl
with theURL
API (e.g.new URL(baseUrl).origin
) and compare origins directly for reliability.Copilot uses AI. Check for mistakes.