mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-20 04:26:53 +00:00
Do some cleanup of GH html
This commit is contained in:
3 files changed
+51
-2
No files matched your search
+6
@@ -22,6 +22,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the link underline off code, where it hides underscores
|
||||
// e.g. PAPERLESS_ALLOWED_HOSTS
|
||||
a code {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.markdown-alert {
|
||||
border-left: 0.25rem solid var(--bs-info);
|
||||
padding: 0.5rem 1rem;
|
||||
|
||||
+20
-1
@@ -8,7 +8,10 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { ReleaseNotesDialogComponent } from './release-notes-dialog.component'
|
||||
import {
|
||||
prepareReleaseHtml,
|
||||
ReleaseNotesDialogComponent,
|
||||
} from './release-notes-dialog.component'
|
||||
|
||||
describe('ReleaseNotesDialogComponent', () => {
|
||||
let component: ReleaseNotesDialogComponent
|
||||
@@ -74,6 +77,22 @@ describe('ReleaseNotesDialogComponent', () => {
|
||||
).toEqual('1 change')
|
||||
})
|
||||
|
||||
it('should open release note links safely and drop svg icons', () => {
|
||||
const html = prepareReleaseHtml(
|
||||
'<div class="markdown-alert"><p class="markdown-alert-title"><svg><path d="M0"></path></svg>Note</p></div>' +
|
||||
'<p><a href="https://github.com/paperless-ngx/paperless-ngx/pull/1" data-hovercard-type="pull_request">#1</a></p>'
|
||||
)
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html')
|
||||
expect(doc.querySelector('svg')).toBeNull()
|
||||
expect(doc.querySelector('.markdown-alert-title').textContent).toEqual(
|
||||
'Note'
|
||||
)
|
||||
const link = doc.querySelector('a')
|
||||
expect(link.getAttribute('target')).toEqual('_blank')
|
||||
expect(link.getAttribute('rel')).toEqual('noopener noreferrer nofollow')
|
||||
expect(link.hasAttribute('data-hovercard-type')).toBe(false)
|
||||
})
|
||||
|
||||
it('should show a message if release notes could not be loaded', () => {
|
||||
create(true)
|
||||
component.load(null)
|
||||
|
||||
+25
-1
@@ -11,6 +11,25 @@ import { SettingsService } from 'src/app/services/settings.service'
|
||||
|
||||
const RELEASES_URL = 'https://github.com/paperless-ngx/paperless-ngx/releases'
|
||||
|
||||
/**
|
||||
* Tweak GitHub release HTML: open links in a new tab, add no referrer etc,
|
||||
* drop inline svgs and GH `data-*` attributes. Angular sanitizes all of this anyway.
|
||||
*/
|
||||
export function prepareReleaseHtml(html: string): string {
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html')
|
||||
doc.querySelectorAll('svg').forEach((svg) => svg.remove())
|
||||
doc.body.querySelectorAll('*').forEach((el) => {
|
||||
for (const attr of Array.from(el.attributes)) {
|
||||
if (attr.name.startsWith('data-')) el.removeAttribute(attr.name)
|
||||
}
|
||||
})
|
||||
doc.querySelectorAll('a').forEach((a) => {
|
||||
a.setAttribute('target', '_blank')
|
||||
a.setAttribute('rel', 'noopener noreferrer nofollow')
|
||||
})
|
||||
return doc.body.innerHTML
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-release-notes-dialog',
|
||||
templateUrl: './release-notes-dialog.component.html',
|
||||
@@ -48,7 +67,12 @@ export class ReleaseNotesDialogComponent {
|
||||
.pipe(first())
|
||||
.subscribe({
|
||||
next: (notes) => {
|
||||
this.releases.set(notes.releases)
|
||||
this.releases.set(
|
||||
notes.releases.map((release) => ({
|
||||
...release,
|
||||
body_html: prepareReleaseHtml(release.body_html),
|
||||
}))
|
||||
)
|
||||
this.loading.set(false)
|
||||
},
|
||||
error: () => {
|
||||
|
||||
Reference in new issue
Block a user