Skip to content

Commit 54ca7bd

Browse files
authored
fix: do not strip package name from description (#2274)
1 parent 5b0bfc7 commit 54ca7bd

File tree

4 files changed

+3
-108
lines changed

4 files changed

+3
-108
lines changed

app/components/Package/Card.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const isExactMatch = computed(() => {
3737
const pkgDescription = useMarkdown(() => ({
3838
text: props.result.package.description ?? '',
3939
plain: true,
40-
packageName: props.result.package.name,
4140
}))
4241
4342
const numberFormatter = useNumberFormatter()

app/composables/useMarkdown.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ interface UseMarkdownOptions {
44
text: string
55
/** When true, renders link text without the anchor tag (useful when inside another link) */
66
plain?: boolean
7-
/** Package name to strip from the beginning of the description (if present) */
8-
packageName?: string
97
}
108

119
export function useMarkdown(options: MaybeRefOrGetter<UseMarkdownOptions>) {
@@ -25,7 +23,7 @@ function stripMarkdownImages(text: string): string {
2523
}
2624

2725
// Strip HTML tags and escape remaining HTML to prevent XSS
28-
function stripAndEscapeHtml(text: string, packageName?: string): string {
26+
function stripAndEscapeHtml(text: string): string {
2927
// First decode any HTML entities in the input
3028
let stripped = decodeHtmlEntities(text)
3129

@@ -45,18 +43,6 @@ function stripAndEscapeHtml(text: string, packageName?: string): string {
4543
(match, codeSpan: string | undefined) => codeSpan ?? '',
4644
)
4745

48-
if (packageName) {
49-
// Trim first to handle leading/trailing whitespace from stripped HTML
50-
stripped = stripped.trim()
51-
// Collapse multiple whitespace into single space
52-
stripped = stripped.replace(/\s+/g, ' ')
53-
// Escape special regex characters in package name
54-
const escapedName = packageName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
55-
// Match package name at the start, optionally followed by: space, dash, colon, hyphen, or just space
56-
const namePattern = new RegExp(`^${escapedName}\\s*[-:—]?\\s*`, 'i')
57-
stripped = stripped.replace(namePattern, '').trim()
58-
}
59-
6046
// Then escape any remaining HTML entities
6147
return stripped
6248
.replace(/&/g, '&amp;')
@@ -67,11 +53,11 @@ function stripAndEscapeHtml(text: string, packageName?: string): string {
6753
}
6854

6955
// Parse simple inline markdown to HTML
70-
function parseMarkdown({ text, packageName, plain }: UseMarkdownOptions): string {
56+
function parseMarkdown({ text, plain }: UseMarkdownOptions): string {
7157
if (!text) return ''
7258

7359
// First strip HTML tags and escape remaining HTML
74-
let html = stripAndEscapeHtml(text, packageName)
60+
let html = stripAndEscapeHtml(text)
7561

7662
// Bold: **text** or __text__
7763
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')

app/pages/package/[[org]]/[name].vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ const versionSecurityMetadata = computed<PackageVersionInfo[]>(() => {
257257
// Process package description
258258
const pkgDescription = useMarkdown(() => ({
259259
text: pkg.value?.description ?? '',
260-
packageName: pkg.value?.name,
261260
}))
262261
263262
// Fetch dependency analysis (lazy, client-side)

test/nuxt/composables/use-markdown.spec.ts

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -196,95 +196,6 @@ describe('useMarkdown', () => {
196196
})
197197
})
198198

199-
describe('packageName prop', () => {
200-
it('strips package name from the beginning of plain text', () => {
201-
const processed = useMarkdown({
202-
text: 'my-package - A great library',
203-
packageName: 'my-package',
204-
})
205-
expect(processed.value).toBe('A great library')
206-
})
207-
208-
it('strips package name with colon separator', () => {
209-
const processed = useMarkdown({
210-
text: 'my-package: A great library',
211-
packageName: 'my-package',
212-
})
213-
expect(processed.value).toBe('A great library')
214-
})
215-
216-
it('strips package name with em dash separator', () => {
217-
const processed = useMarkdown({
218-
text: 'my-package — A great library',
219-
packageName: 'my-package',
220-
})
221-
expect(processed.value).toBe('A great library')
222-
})
223-
224-
it('strips package name without separator', () => {
225-
const processed = useMarkdown({
226-
text: 'my-package A great library',
227-
packageName: 'my-package',
228-
})
229-
expect(processed.value).toBe('A great library')
230-
})
231-
232-
it('is case-insensitive', () => {
233-
const processed = useMarkdown({
234-
text: 'MY-PACKAGE - A great library',
235-
packageName: 'my-package',
236-
})
237-
expect(processed.value).toBe('A great library')
238-
})
239-
240-
it('does not strip package name from middle of text', () => {
241-
const processed = useMarkdown({
242-
text: 'A great my-package library',
243-
packageName: 'my-package',
244-
})
245-
expect(processed.value).toBe('A great my-package library')
246-
})
247-
248-
it('handles scoped package names', () => {
249-
const processed = useMarkdown({
250-
text: '@org/my-package - A great library',
251-
packageName: '@org/my-package',
252-
})
253-
expect(processed.value).toBe('A great library')
254-
})
255-
256-
it('handles package names with special regex characters', () => {
257-
const processed = useMarkdown({
258-
text: 'pkg.name+test - A great library',
259-
packageName: 'pkg.name+test',
260-
})
261-
expect(processed.value).toBe('A great library')
262-
})
263-
264-
it('strips package name from HTML-containing descriptions', () => {
265-
const processed = useMarkdown({
266-
text: '<b>my-package</b> - A great library',
267-
packageName: 'my-package',
268-
})
269-
expect(processed.value).toBe('A great library')
270-
})
271-
272-
it('strips package name from descriptions with markdown images', () => {
273-
const processed = useMarkdown({
274-
text: '![badge](https://badge.svg) my-package - A great library',
275-
packageName: 'my-package',
276-
})
277-
expect(processed.value).toBe('A great library')
278-
})
279-
280-
it('does nothing when packageName is not provided', () => {
281-
const processed = useMarkdown({
282-
text: 'my-package - A great library',
283-
})
284-
expect(processed.value).toBe('my-package - A great library')
285-
})
286-
})
287-
288199
describe('HTML tag stripping', () => {
289200
it('strips simple HTML tags but keeps content', () => {
290201
const processed = useMarkdown({ text: '<b>bold text</b> here' })

0 commit comments

Comments
 (0)