Commit MetaInfo

Revisão7029b9124a49f56433d92a0110b05e83a9664f13 (tree)
Hora2020-03-20 14:21:46
Autorumorigu <umorigu@gmai...>
Commiterumorigu

Mensagem de Log

BugTrack/2508 Fix search result (FullWidth char / Ignore case)

Mudança Sumário

Diff

--- a/skin/search2.js
+++ b/skin/search2.js
@@ -238,17 +238,36 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function
238238 kanaMap = map
239239 }
240240 /**
241+ * Hankaku to Zenkaku.
242+ *
243+ * @param {String} hankakuChar
244+ * @returns {String}
245+ */
246+ function toZenkaku (hankakuChar) {
247+ if (hankakuChar.length !== 1) {
248+ return hankakuChar
249+ }
250+ var zenkakuChar = String.fromCharCode(hankakuChar.charCodeAt(0) + 0xfee0)
251+ if (!String.prototype.normalize) {
252+ return hankakuChar
253+ }
254+ if (zenkakuChar.normalize('NFKC') === hankakuChar) {
255+ return zenkakuChar
256+ }
257+ return hankakuChar
258+ }
259+ /**
241260 * @param {searchText} searchText
242261 * @type RegExp
243262 */
244263 function textToRegex (searchText) {
245264 if (!searchText) return null
246- // 1:Symbol 2:Katakana 3:Hiragana
247- var regRep = /([\\^$.*+?()[\]{}|])|([\u30a1-\u30f6])|([\u3041-\u3096])/g
248- var replacementFunc = function (m, m1, m2, m3) {
265+ // 1: Alphabet 2:Katakana 3:Hiragana 4:Other symbols
266+ var regRep = /([a-zA-Z0-9])|([\u30a1-\u30f6])|([\u3041-\u3096])|([\u0021-\u007e])/ig
267+ var replacementFunc = function (m, m1, m2, m3, m4) {
249268 if (m1) {
250- // Symbol - escape with prior backslach
251- return '\\' + m1
269+ // [a-zA-Z0-9]
270+ return '[' + m1 + toZenkaku(m1) + ']'
252271 } else if (m2) {
253272 // Katakana
254273 var r = '(?:' + String.fromCharCode(m2.charCodeAt(0) - 0x60) +
@@ -267,6 +286,9 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function
267286 }
268287 r2 += ')'
269288 return r2
289+ } else if (m4) {
290+ // Other symbols
291+ return '[' + '\\' + m4 + toZenkaku(m4) + ']'
270292 }
271293 return m
272294 }
Show on old repository browser