Skip to content

Commit

Permalink
Merge pull request #720 from traPtitech/feat/validate-uuid
Browse files Browse the repository at this point in the history
idパラメータがUUIDとしてvalidかどうかをチェックする close #571
  • Loading branch information
sapphi-red authored Oct 5, 2022
2 parents 8118f52 + ae11b08 commit c4ef6ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/MessageWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { render } from '../markdown/markdown'
import { getStore } from '../store'
import { QuotedMessage } from './QuotedMessage'
import { File } from './File'
import { dateToString } from '../utils'
import { dateToString, isValidUuid } from '../utils'
import { EmbeddingFile, EmbeddingMessage } from '@traptitech/traq-markdown-it'

import '../markdown/markdown.scss'
Expand Down Expand Up @@ -35,6 +35,15 @@ const InnerMessageWidget = async (
</article>
`
}
if (!isValidUuid(id)) {
return html`
<article class="main-message message" data-is-error>
<main class="error">
不正なメッセージIDです。URLが間違っていませんか?
</main>
</article>
`
}

try {
const message = (await apis.getMessage(id)).data
Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export const dateToString = (date: string): string => {

return `${day} ${time}`
}

export const isValidUuid = (uuidStr: string) =>
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(uuidStr)

0 comments on commit c4ef6ee

Please sign in to comment.