Remove invisible characters from display names

This commit is contained in:
silverpill 2023-02-10 00:21:04 +00:00
parent 72a047862f
commit f95fac41f6
6 changed files with 35 additions and 12 deletions

View file

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased] ## [Unreleased]
### Changed
- Remove invisible characters from display names.
## [1.13.0] - 2023-02-06 ## [1.13.0] - 2023-02-06
### Added ### Added

View file

@ -89,7 +89,14 @@ export class ProfileWrapper {
} }
getDisplayName(): string { getDisplayName(): string {
return this.display_name || this.username let cleanDisplayName
if (this.display_name) {
// Replace control characters
cleanDisplayName = this.display_name.replace(/\p{C}/gu, "")
} else {
cleanDisplayName = this.display_name
}
return cleanDisplayName || this.username
} }
getVerifiedEthereumAddress(): string | null { getVerifiedEthereumAddress(): string | null {

View file

@ -6,7 +6,7 @@
:to="{ name: 'profile', params: { profileId: post.account.id }}" :to="{ name: 'profile', params: { profileId: post.account.id }}"
:title="getActorAddress(post.account)" :title="getActorAddress(post.account)"
> >
{{ post.account.display_name || post.account.username }} {{ author.getDisplayName() }}
</router-link> </router-link>
<span>reposted</span> <span>reposted</span>
</div> </div>
@ -27,14 +27,15 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { $ } from "vue/macros" import { $, $computed } from "vue/macros"
import type { Post as PostObject } from "@/api/posts" import type { Post as PostObject } from "@/api/posts"
import { ProfileWrapper } from "@/api/users"
import Post from "@/components/Post.vue" import Post from "@/components/Post.vue"
import { useInstanceInfo } from "@/store/instance" import { useInstanceInfo } from "@/store/instance"
/* eslint-disable-next-line no-undef */ /* eslint-disable-next-line no-undef */
defineProps<{ const props = defineProps<{
post: PostObject, post: PostObject,
}>() }>()
/* eslint-disable-next-line no-undef */ /* eslint-disable-next-line no-undef */
@ -42,6 +43,8 @@ const emit = defineEmits<{(event: "post-deleted", postId: string): void}>()
const { getActorAddress } = $(useInstanceInfo()) const { getActorAddress } = $(useInstanceInfo())
const author = $computed(() => new ProfileWrapper(props.post.account))
function onPostDeleted(postId: string) { function onPostDeleted(postId: string) {
emit("post-deleted", postId) emit("post-deleted", postId)
} }

View file

@ -7,7 +7,7 @@
<div class="avatar-row"> <div class="avatar-row">
<avatar :profile="profile"></avatar> <avatar :profile="profile"></avatar>
<div class="name-group"> <div class="name-group">
<div class="display-name">{{ profile.display_name || profile.username }}</div> <div class="display-name">{{ profile.getDisplayName() }}</div>
<div class="actor-address">@{{ getActorAddress(profile) }}</div> <div class="actor-address">@{{ getActorAddress(profile) }}</div>
</div> </div>
</div> </div>
@ -23,17 +23,21 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { Profile } from "@/api/users" import { $computed } from "vue/macros"
import { Profile, ProfileWrapper } from "@/api/users"
import Avatar from "@/components/Avatar.vue" import Avatar from "@/components/Avatar.vue"
import { useInstanceInfo } from "@/store/instance" import { useInstanceInfo } from "@/store/instance"
/* eslint-disable-next-line no-undef */ /* eslint-disable-next-line no-undef */
defineProps<{ const props = defineProps<{
profile: Profile, profile: Profile,
compact: boolean, compact: boolean,
}>() }>()
const { getActorAddress } = useInstanceInfo() const { getActorAddress } = useInstanceInfo()
const profile = $computed(() => new ProfileWrapper(props.profile))
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View file

@ -2,23 +2,27 @@
<div class="profile"> <div class="profile">
<avatar :profile="profile"></avatar> <avatar :profile="profile"></avatar>
<div class="name"> <div class="name">
<div class="display-name">{{ profile.display_name || profile.username }}</div> <div class="display-name">{{ profile.getDisplayName() }}</div>
<div class="actor-address">@{{ getActorAddress(profile) }}</div> <div class="actor-address">@{{ getActorAddress(profile) }}</div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { Profile } from "@/api/users" import { $computed } from "vue/macros"
import { Profile, ProfileWrapper } from "@/api/users"
import Avatar from "@/components/Avatar.vue" import Avatar from "@/components/Avatar.vue"
import { useInstanceInfo } from "@/store/instance" import { useInstanceInfo } from "@/store/instance"
const { getActorAddress } = useInstanceInfo() const { getActorAddress } = useInstanceInfo()
/* eslint-disable-next-line no-undef */ /* eslint-disable-next-line no-undef */
defineProps<{ const props = defineProps<{
profile: Profile, profile: Profile,
}>() }>()
const profile = $computed(() => new ProfileWrapper(props.profile))
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View file

@ -70,6 +70,7 @@ import { $ } from "vue/macros"
import { PAGE_SIZE } from "@/api/common" import { PAGE_SIZE } from "@/api/common"
import { updateNotificationMarker } from "@/api/markers" import { updateNotificationMarker } from "@/api/markers"
import { getNotifications, Notification } from "@/api/notifications" import { getNotifications, Notification } from "@/api/notifications"
import { ProfileWrapper } from "@/api/users"
import Avatar from "@/components/Avatar.vue" import Avatar from "@/components/Avatar.vue"
import Post from "@/components/Post.vue" import Post from "@/components/Post.vue"
import SidebarLayout from "@/components/SidebarLayout.vue" import SidebarLayout from "@/components/SidebarLayout.vue"
@ -94,8 +95,8 @@ onMounted(async () => {
}) })
function getSenderName(notification: Notification): string { function getSenderName(notification: Notification): string {
const sender = notification.account const sender = new ProfileWrapper(notification.account)
return sender.display_name || sender.username return sender.getDisplayName()
} }
function getSenderInfo(notification: Notification): string { function getSenderInfo(notification: Notification): string {