Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/Compare/PackageSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ onClickOutside(containerRef, () => {
v-if="result.description"
class="text-xs text-fg-muted truncate mt-0.5 w-full block"
>
{{ decodeHtmlEntities(result.description) }}
{{ stripHtmlTags(decodeHtmlEntities(result.description)) }}
</span>
</ButtonBase>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/components/Package/TableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const allMaintainersText = computed(() => {
v-if="isColumnVisible('description')"
class="py-2 px-3 text-sm text-fg-muted max-w-xs truncate"
>
{{ decodeHtmlEntities(pkg.description || '-') }}
{{ stripHtmlTags(decodeHtmlEntities(pkg.description || '-')) }}
Copy link
Copy Markdown
Contributor

@vmrjnvc vmrjnvc Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now with this changes there could be full empty descriptions displayed, but there should be dash if there is no description

Image

so correct should be {{ stripHtmlTags(decodeHtmlEntities(pkg.description || '')) || '-'}} because if there is just html in the description, all will be removed and we don't have fallback

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! would you like to open a quick PR for that? 🙏🏼

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, no problem!

here #1763

</td>

<!-- Downloads -->
Expand Down
4 changes: 4 additions & 0 deletions shared/utils/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
export function decodeHtmlEntities(text: string): string {
return text.replace(/&(?:amp|lt|gt|quot|apos|nbsp|#39);/g, match => htmlEntities[match] || match)
}

export function stripHtmlTags(text: string): string {
Comment thread
danielroe marked this conversation as resolved.
return text.replace(/<[^>]*>/g, '')
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
25 changes: 24 additions & 1 deletion test/unit/shared/utils/html.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { decodeHtmlEntities } from '../../../../shared/utils/html'
import { decodeHtmlEntities, stripHtmlTags } from '../../../../shared/utils/html'

describe('decodeHtmlEntities', () => {
it.each([
Expand All @@ -26,3 +26,26 @@ describe('decodeHtmlEntities', () => {
expect(decodeHtmlEntities('&unknown;')).toBe('&unknown;')
})
})

describe('stripHtmlTags', () => {
it('removes simple HTML tags', () => {
expect(stripHtmlTags('<b>bold</b>')).toBe('bold')
})

it('removes anchor tags keeping text content', () => {
expect(stripHtmlTags('<a href="https://example.com">link</a>')).toBe('link')
})

it('removes self-closing tags', () => {
expect(stripHtmlTags('before<br/>after')).toBe('beforeafter')
})

it('leaves plain text unchanged', () => {
expect(stripHtmlTags('no tags here')).toBe('no tags here')
})

it('works with decodeHtmlEntities to clean descriptions', () => {
const raw = '&lt;a href=&quot;url&quot;&gt;link&lt;/a&gt; and text'
expect(stripHtmlTags(decodeHtmlEntities(raw))).toBe('link and text')
})
})
Loading