Skip to content

Commit 1a00022

Browse files
Yukaiijackycute
andcommitted
fix: unwrap the geo div and throw error when input
location search not found also fix the CSP rule that the img with data src might be violated Signed-off-by: Yukai Huang <[email protected]> Co-authored-by: Max Wu <[email protected]>
1 parent 8a05276 commit 1a00022

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/csp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var defaultDirectives = {
77
defaultSrc: ['\'self\''],
88
scriptSrc: ['\'self\'', 'vimeo.com', 'https://gist.github.com', 'www.slideshare.net', 'https://query.yahooapis.com', '\'unsafe-eval\''],
99
// ^ TODO: Remove unsafe-eval - webpack script-loader issues https://github.com/hackmdio/codimd/issues/594
10-
imgSrc: ['*'],
10+
imgSrc: ['*', 'data:'],
1111
styleSrc: ['\'self\'', '\'unsafe-inline\'', 'https://github.githubassets.com'], // unsafe-inline is required for some libs, plus used in views
1212
fontSrc: ['\'self\'', 'data:', 'https://public.slidesharecdn.com'],
1313
objectSrc: ['*'], // Chrome PDF viewer treats PDFs as objects :/

public/js/extra.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,13 @@ export function finishView (view) {
453453
console.warn(err)
454454
}
455455
})
456+
// geo map
456457
view.find('div.geo.raw').removeClass('raw').each(async function (key, value) {
457458
const $elem = $(value).parent().parent()
458459
const $value = $(value)
459460
const content = $value.text()
461+
$value.unwrap()
462+
460463
try {
461464
let position, zoom
462465
if (content.match(/^[\d.,\s]+$/)) {
@@ -466,6 +469,9 @@ export function finishView (view) {
466469
} else {
467470
// parse value as address
468471
const data = await fetch(`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(content)}&format=json`).then(r => r.json())
472+
if (!data || !data.length) {
473+
throw new Error('Location not found')
474+
}
469475
const { lat, lon } = data[0]
470476
position = [lat, lon]
471477
}

0 commit comments

Comments
 (0)