zhangkaitao / es

JavaEE项目开发脚手架(我的公众号:kaitao-1234567,我的新书:《亿级流量网站架构核心技术》)
https://github.com/zhangkaitao/es
Apache License 2.0
2.17k stars 1.59k forks source link

removeSearchParam 中的正则匹配bug #37

Closed apei830 closed 10 years ago

apei830 commented 10 years ago

removeSearchParam : function(url, form) { $.each(form.serializeArray(), function() { var name = this.name; url = url.replace(new RegExp(name + "=.?&","g"), ''); url = url.replace(new RegExp("[&\?]" + name + "=.$","g"), ''); }); return url; },

应该使用非饥渴模式 url = url.replace(new RegExp(name + "=.&","g"), ''); 饥渴 url = url.replace(new RegExp(name + "=.?&","g"), ''); 非饥渴,尽量少匹配

原来的正则会有如下bug:

http://localhost:9090/eas/admin/showcase/sample/sample/list2.html?aaa=12&bbb=&ccc=&page.orderBy=email&page.order=asc

当循环form里的参数aaa时,会一直匹配到page.order为止,中间的所有参数都会被remove掉,变成: http://localhost:9090/eas/admin/showcase/sample/sample/list2.html?page.order=asc

zhangkaitao commented 10 years ago

fixed