Skip to content
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

古いiOSで正規表現の後読みが使えない問題を修正 #4507

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/markdown/internalLinkEmbedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

// URLの一部になっているときは置換しない (URLの正規表現は完全ではない)
const urlRegexStr = '(?:https?://)?(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]+(?:/[^/]+)*/?'
const urlStartRegex = new RegExp(`^${urlRegexStr}`)
const mentionRegex = new RegExp(
`(?<!${urlRegexStr}):?[@@]([^\\s@@.]{0,31}[^\\s@@:.])\\.?`,
`(${urlRegexStr})?:?[@@]([^\\s@@.]{0,31}[^\\s@@:.])\\.?`,
'g'
)
const userStartsRegex = /^[@@]([a-zA-Z0-9_-]{1,32})/g
const channelRegex = new RegExp(
`(?<!${urlRegexStr})[##]([a-zA-Z0-9_/-]+)`,
'g'
)
const channelRegex = new RegExp(`(${urlRegexStr})?[##]([a-zA-Z0-9_/-]+)`, 'g')

const backQuote = '`'
const dollar = '$'
Expand Down Expand Up @@ -122,6 +120,8 @@ const replaceAll = (m: string, getters: Readonly<ReplaceGetters>) => {

const replaceMention = (m: string, getters: Readonly<UserAndGroupGetters>) => {
return m.replace(mentionRegex, s => {
const urlStart = s.match(urlStartRegex)
if (urlStart && urlStart.length !== 0) return s
// 始まりが:なものを除外
if (s.startsWith(':')) return s
// 終わりが.のものを除外
Expand Down Expand Up @@ -155,6 +155,8 @@ const replaceMention = (m: string, getters: Readonly<UserAndGroupGetters>) => {

const replaceChannel = (m: string, getter: Readonly<ChannelGetter>) => {
return m.replace(channelRegex, s => {
const urlStart = s.match(urlStartRegex)
if (urlStart && urlStart.length !== 0) return s
// .slice(1)は先頭の#を消すため
// 小文字化はgetter内で行う
const t = s.slice(1)
Expand Down
Loading