Authored by yyq

Merge branch 'hotfix/searchHistory' into release/6.4

@@ -154,6 +154,8 @@ exports.special = (req, res, next) => { @@ -154,6 +154,8 @@ exports.special = (req, res, next) => {
154 let specialId = params.specialsale_id || params.specialsaleId, // 专区ID 154 let specialId = params.specialsale_id || params.specialsaleId, // 专区ID
155 promotion = params.promotion; // 促销ID 155 promotion = params.promotion; // 促销ID
156 156
  157 + specialId = parseInt(`0${specialId}`, 10);
  158 +
157 if (!specialId && !promotion) { 159 if (!specialId && !promotion) {
158 return next(); 160 return next();
159 } 161 }
@@ -142,7 +142,13 @@ const searchFilterBrands = (req, res, next) => { @@ -142,7 +142,13 @@ const searchFilterBrands = (req, res, next) => {
142 142
143 const searchHistory = (req, res) => { 143 const searchHistory = (req, res) => {
144 let history = req.cookies['_History'] || ''; //eslint-disable-line 144 let history = req.cookies['_History'] || ''; //eslint-disable-line
145 - let q = req.query.query ? _.trim(decodeURIComponent(req.query.query)) : ''; 145 + let q = _.trim(req.query.query || '');
  146 +
  147 + try {
  148 + q = decodeURIComponent(q);
  149 + } catch (e) { //eslint-disable-line
  150 + q = '';
  151 + }
146 152
147 history = _.filter(history.split(','), old => old && old !== q); 153 history = _.filter(history.split(','), old => old && old !== q);
148 154
@@ -268,8 +268,10 @@ function getBrands4Filter(params) { @@ -268,8 +268,10 @@ function getBrands4Filter(params) {
268 delete params.callback; 268 delete params.callback;
269 } 269 }
270 270
271 - if (params.specialsale_id) {  
272 - return this.saleApi.getSaleSpecialAsync(params.specialsale_id).then(special => { 271 + const specialId = parseInt(`0${params.specialsale_id || ''}`, 10);
  272 +
  273 + if (specialId) {
  274 + return this.saleApi.getSaleSpecialAsync(specialId).then(special => {
273 if (special && special.data) { 275 if (special && special.data) {
274 let data = special.data; 276 let data = special.data;
275 277
@@ -3,14 +3,12 @@ @@ -3,14 +3,12 @@
3 const urlEncode = require('urlencode'); 3 const urlEncode = require('urlencode');
4 const _ = require('lodash'); 4 const _ = require('lodash');
5 const helpers = global.yoho.helpers; 5 const helpers = global.yoho.helpers;
6 -const allowSubDomain = ['list', 'search'];  
7 -  
8 6
9 module.exports = (req, res, next) => { 7 module.exports = (req, res, next) => {
10 - let query = req.query.query; 8 + let query = _.trim(req.query.query);
11 let subDomain = req.subdomains[0]; 9 let subDomain = req.subdomains[0];
12 10
13 - if (query && _.includes(allowSubDomain, subDomain)) { 11 + if (query) {
14 try { 12 try {
15 decodeURIComponent(query); 13 decodeURIComponent(query);
16 return next(); 14 return next();