Skip to content

Commit 2bc38ed

Browse files
pawelngeihiyuki2578
authored andcommitted
Escape HTML in profile name preview in profile settings (mastodon#9446)
* fix non-escaped html in the profile settings * provide a default profile text in case if there's no custom one * update haml syntax * simplify default profile name to username * sanitize user-input html but display emojified icons
1 parent f666956 commit 2bc38ed

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

app/javascript/packs/public.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import escapeTextContentForBrowser from 'escape-html';
12
import loadPolyfills from '../mastodon/load_polyfills';
23
import ready from '../mastodon/ready';
34
import { start } from '../mastodon/common';
@@ -133,9 +134,12 @@ function main() {
133134

134135
delegate(document, '#account_display_name', 'input', ({ target }) => {
135136
const name = document.querySelector('.card .display-name strong');
136-
137137
if (name) {
138-
name.innerHTML = emojify(target.value);
138+
if (target.value) {
139+
name.innerHTML = emojify(escapeTextContentForBrowser(target.value));
140+
} else {
141+
name.textContent = document.querySelector('#default_account_display_name').textContent;
142+
}
139143
}
140144
});
141145

app/views/application/_card.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
= image_tag account.avatar.url, alt: '', width: 48, height: 48, class: 'u-photo'
1010

1111
.display-name
12+
%span{id: "default_account_display_name", style: "display:none;"}= account.username
1213
%bdi
1314
%strong.emojify.p-name= display_name(account, custom_emojify: true)
1415
%span

0 commit comments

Comments
 (0)