Skip to content

Commit 1622578

Browse files
authored
Merge pull request #974 from Koooooo-7/develop
[fix]#972 when 'logo' is set, 'name' is not set correctly inside the 'alt' as same as without 'logo' set.
2 parents 378d7bb + c403318 commit 1622578

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Diff for: src/core/render/tpl.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {isMobile} from '../util/env'
2+
import {escapeString} from '../util/core'
23
/**
34
* Render github corner
45
* @param {Object} data
@@ -30,6 +31,9 @@ export function corner(data, cornerExternalLinkTarge) {
3031
* Render main content
3132
*/
3233
export function main(config) {
34+
35+
const name = config.name? escapeString(config.name):''
36+
3337
const aside =
3438
'<button class="sidebar-toggle" aria-label="Menu">' +
3539
'<div class="sidebar-toggle-button">' +
@@ -39,9 +43,9 @@ export function main(config) {
3943
'<aside class="sidebar">' +
4044
(config.name ?
4145
`<h1 class="app-name"><a class="app-name-link" data-nosearch>${
42-
config.logo ?
43-
`<img alt=${config.name} src=${config.logo}>` :
44-
config.name
46+
config.logo ?
47+
`<img alt="${name}" src=${config.logo}>` :
48+
name
4549
}</a></h1>` :
4650
'') +
4751
'<div class="sidebar-nav"><!--sidebar--></div>' +

Diff for: src/core/util/core.js

+16
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ export function noop() {}
5656
export function isFn(obj) {
5757
return typeof obj === 'function'
5858
}
59+
60+
/**
61+
* escape String
62+
*/
63+
export function escapeString(string) {
64+
const entityMap = {
65+
'&': '&amp;',
66+
'<': '&lt;',
67+
'>': '&gt;',
68+
'"': '&quot;',
69+
'\'': '&#39;',
70+
'/': '&#x2F;'
71+
}
72+
73+
return String(string).replace(/[&<>"'/]/g, s => entityMap[s])
74+
}

0 commit comments

Comments
 (0)