Skip to content

Commit e225060

Browse files
authored
chore: display tag title as string in delete dialog (#2904)
1 parent 974fcef commit e225060

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

packages/utils/src/Domain/Utils/Utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { sanitize } from 'dompurify'
3-
import { find, isArray, mergeWith, remove, uniq, uniqWith } from 'lodash'
3+
import { escape, find, isArray, mergeWith, remove, uniq, uniqWith } from 'lodash'
44
import { AnyRecord } from '@standardnotes/common'
55

66
const collator = typeof Intl !== 'undefined' ? new Intl.Collator('en', { numeric: true }) : undefined
@@ -612,6 +612,10 @@ export function sanitizeHtmlString(html: string): string {
612612
return sanitize(html)
613613
}
614614

615+
export function escapeHtmlString(html: string): string {
616+
return escape(html)
617+
}
618+
615619
let sharedDateFormatter: unknown
616620
export function dateToLocalizedString(date: Date): string {
617621
if (typeof Intl !== 'undefined' && Intl.DateTimeFormat && typeof navigator !== 'undefined') {

packages/web/src/javascripts/Constants/Strings.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Platform, SNApplication } from '@standardnotes/snjs'
1+
import { escapeHtmlString, Platform, SNApplication } from '@standardnotes/snjs'
22
import { getPlatform, isDesktopApplication } from '../Utils'
33

44
/** @generic */
@@ -39,9 +39,10 @@ export const STRING_EDIT_LOCKED_ATTEMPT =
3939
export const STRING_RESTORE_LOCKED_ATTEMPT =
4040
"This note has editing disabled. If you'd like to restore it to a previous revision, enable editing and try again."
4141
export function StringDeleteNote(title: string, permanently: boolean) {
42+
const escapedTitle = escapeHtmlString(title)
4243
return permanently
43-
? `Are you sure you want to permanently delete ${title}?`
44-
: `Are you sure you want to move ${title} to the trash?`
44+
? `Are you sure you want to permanently delete ${escapedTitle}?`
45+
: `Are you sure you want to move ${escapedTitle} to the trash?`
4546
}
4647
export function StringEmptyTrash(count: number) {
4748
return `Are you sure you want to permanently delete ${count} note(s)?`
@@ -135,17 +136,19 @@ export const StringUtils = {
135136
},
136137
deleteNotes(permanently: boolean, notesCount = 1, title?: string): string {
137138
if (notesCount === 1) {
139+
const escapedTitle = escapeHtmlString(title || '')
138140
return permanently
139-
? `Are you sure you want to permanently delete ${title}?`
140-
: `Are you sure you want to move ${title} to the trash?`
141+
? `Are you sure you want to permanently delete ${escapedTitle}?`
142+
: `Are you sure you want to move ${escapedTitle} to the trash?`
141143
} else {
142144
return permanently
143145
? 'Are you sure you want to permanently delete these notes?'
144146
: 'Are you sure you want to move these notes to the trash?'
145147
}
146148
},
147149
deleteFile(title: string): string {
148-
return `Are you sure you want to permanently delete ${title}?`
150+
const escapedTitle = escapeHtmlString(title)
151+
return `Are you sure you want to permanently delete ${escapedTitle}?`
149152
},
150153
archiveLockedNotesAttempt(archive: boolean, notesCount = 1): string {
151154
const archiveString = archive ? 'archive' : 'unarchive'
@@ -158,4 +161,12 @@ export const StringUtils = {
158161
? "This note has editing disabled. If you'd like to delete it, enable editing, and try again."
159162
: "One or more of these notes have editing disabled. If you'd like to delete them, make sure editing is enabled on all of them, and try again."
160163
},
164+
deleteTag(title: string): string {
165+
const escapedTitle = escapeHtmlString(title)
166+
return `Delete tag "${escapedTitle}"?`
167+
},
168+
cannotUploadFile(name: string): string {
169+
const escapedName = escapeHtmlString(name)
170+
return `Cannot upload file "${escapedName}"`
171+
},
161172
}

packages/web/src/javascripts/Controllers/FilesController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
168168

169169
deleteFile = async (file: FileItem) => {
170170
const shouldDelete = await confirmDialog({
171-
text: `Are you sure you want to permanently delete "${file.name}"?`,
171+
text: StringUtils.deleteFile(file.name),
172172
confirmButtonStyle: 'danger',
173173
})
174174
if (shouldDelete) {
@@ -440,7 +440,7 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
440440
`This file exceeds the limits supported in this browser. To upload files greater than ${
441441
this.maxFileSize / BYTES_IN_ONE_MEGABYTE
442442
}MB, please use the desktop application or the Chrome browser.`,
443-
`Cannot upload file "${file.name}"`,
443+
StringUtils.cannotUploadFile(file.name),
444444
)
445445
.catch(console.error)
446446
return true

packages/web/src/javascripts/Controllers/Navigation/NavigationController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
VaultDisplayService,
77
VaultDisplayServiceEvent,
88
} from '@standardnotes/ui-services'
9-
import { STRING_DELETE_TAG } from '@/Constants/Strings'
9+
import { STRING_DELETE_TAG, StringUtils } from '@/Constants/Strings'
1010
import { SMART_TAGS_FEATURE_NAME } from '@/Constants/Constants'
1111
import {
1212
ContentType,
@@ -604,7 +604,7 @@ export class NavigationController
604604
let shouldDelete = !userTriggered
605605
if (userTriggered) {
606606
shouldDelete = await confirmDialog({
607-
title: `Delete tag "${tag.title}"?`,
607+
title: StringUtils.deleteTag(tag.title),
608608
text: STRING_DELETE_TAG,
609609
confirmButtonStyle: 'danger',
610610
})

0 commit comments

Comments
 (0)