Skip to content

Commit

Permalink
[fix] when 'logo' is set, 'name' is not set correctly inside the 'alt…
Browse files Browse the repository at this point in the history
…' field.
  • Loading branch information
Koooooo-7 committed Dec 7, 2019
1 parent e61410a commit c403318
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/render/tpl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {isMobile} from '../util/env'
import {escapeString} from '../util/core'
/**
* Render github corner
* @param {Object} data
Expand Down Expand Up @@ -30,6 +31,9 @@ export function corner(data, cornerExternalLinkTarge) {
* Render main content
*/
export function main(config) {

const name = config.name? escapeString(config.name):''

const aside =
'<button class="sidebar-toggle">' +
'<div class="sidebar-toggle-button">' +
Expand All @@ -39,9 +43,9 @@ export function main(config) {
'<aside class="sidebar">' +
(config.name ?
`<h1 class="app-name"><a class="app-name-link" data-nosearch>${
config.logo ?
`<img alt=${config.name} src=${config.logo}>` :
config.name
config.logo ?
`<img alt="${name}" src=${config.logo}>` :
name
}</a></h1>` :
'') +
'<div class="sidebar-nav"><!--sidebar--></div>' +
Expand Down
16 changes: 16 additions & 0 deletions src/core/util/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,19 @@ export function noop() {}
export function isFn(obj) {
return typeof obj === 'function'
}

/**
* escape String
*/
export function escapeString(string) {
const entityMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#39;',
'/': '&#x2F;'
}

return String(string).replace(/[&<>"'/]/g, s => entityMap[s])
}

0 comments on commit c403318

Please sign in to comment.