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 <yukaihuangtw@gmail.com>
Co-authored-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
Yukai Huang 2020-02-28 15:46:44 +08:00
parent 8a05276339
commit 1a000226b0
No known key found for this signature in database
GPG Key ID: D4D3B2F0E99D4914
2 changed files with 7 additions and 1 deletions

View File

@ -7,7 +7,7 @@ var defaultDirectives = {
defaultSrc: ['\'self\''],
scriptSrc: ['\'self\'', 'vimeo.com', 'https://gist.github.com', 'www.slideshare.net', 'https://query.yahooapis.com', '\'unsafe-eval\''],
// ^ TODO: Remove unsafe-eval - webpack script-loader issues https://github.com/hackmdio/codimd/issues/594
imgSrc: ['*'],
imgSrc: ['*', 'data:'],
styleSrc: ['\'self\'', '\'unsafe-inline\'', 'https://github.githubassets.com'], // unsafe-inline is required for some libs, plus used in views
fontSrc: ['\'self\'', 'data:', 'https://public.slidesharecdn.com'],
objectSrc: ['*'], // Chrome PDF viewer treats PDFs as objects :/

View File

@ -453,10 +453,13 @@ export function finishView (view) {
console.warn(err)
}
})
// geo map
view.find('div.geo.raw').removeClass('raw').each(async function (key, value) {
const $elem = $(value).parent().parent()
const $value = $(value)
const content = $value.text()
$value.unwrap()
try {
let position, zoom
if (content.match(/^[\d.,\s]+$/)) {
@ -466,6 +469,9 @@ export function finishView (view) {
} else {
// parse value as address
const data = await fetch(`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(content)}&format=json`).then(r => r.json())
if (!data || !data.length) {
throw new Error('Location not found')
}
const { lat, lon } = data[0]
position = [lat, lon]
}