fix(backend): fix handling of invalid urls in user profile (#15635)
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
0402866b43
commit
db5c127cdd
|
@ -8,7 +8,7 @@
|
||||||
- 自動でバックアップされるように
|
- 自動でバックアップされるように
|
||||||
|
|
||||||
### Server
|
### Server
|
||||||
-
|
- Fix: プロフィール追加情報で無効なURLに入力された場合に照会エラーを出るのを修正
|
||||||
|
|
||||||
|
|
||||||
## 2025.3.1
|
## 2025.3.1
|
||||||
|
|
|
@ -499,11 +499,28 @@ export class ApRendererService {
|
||||||
this.userProfilesRepository.findOneByOrFail({ userId: user.id }),
|
this.userProfilesRepository.findOneByOrFail({ userId: user.id }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const tryRewriteUrl = (maybeUrl: string) => {
|
||||||
|
const urlSafeRegex = /^(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/;
|
||||||
|
try {
|
||||||
|
const match = maybeUrl.match(urlSafeRegex);
|
||||||
|
if (!match) {
|
||||||
|
return maybeUrl;
|
||||||
|
}
|
||||||
|
const urlPart = match[0];
|
||||||
|
const urlPartParsed = new URL(urlPart);
|
||||||
|
const restPart = maybeUrl.slice(match[0].length);
|
||||||
|
|
||||||
|
return `<a href="${urlPartParsed.href}" rel="me nofollow noopener" target="_blank">${urlPart}</a>${restPart}`;
|
||||||
|
} catch (e) {
|
||||||
|
return maybeUrl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const attachment = profile.fields.map(field => ({
|
const attachment = profile.fields.map(field => ({
|
||||||
type: 'PropertyValue',
|
type: 'PropertyValue',
|
||||||
name: field.name,
|
name: field.name,
|
||||||
value: (field.value.startsWith('http://') || field.value.startsWith('https://'))
|
value: (field.value.startsWith('http://') || field.value.startsWith('https://'))
|
||||||
? `<a href="${new URL(field.value).href}" rel="me nofollow noopener" target="_blank">${new URL(field.value).href}</a>`
|
? tryRewriteUrl(field.value)
|
||||||
: field.value,
|
: field.value,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue