[ https://issues.apache.org/jira/browse/WICKET-3519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13009277#comment-13009277 ]
Max Raba edited comment on WICKET-3519 at 3/21/11 6:44 PM: ----------------------------------------------------------- Hi there, we also experienced this problem with Wicket 1.4.15. We found out that the JavascriptStripper did not recognize the regular expression in the booleasn expression (xx && !/!=/) which is used in jquery-1.5.1 prior to the comment which is described above. Actually the regular expression is recognized at the second slash. Therefore the parsing breaks because the regex is not terminated correctly and ugly things happen (like the expression getting terminated by "*/*". A much more shorter example would be: var test = function () { var c = "!="; /* from jquery 1.5.1 */ if ( !l.match.PSEUDO.test(c) && !/!=/.test(c)) { alert("/something bad will happen */* "); } var importantFunction = function () {alert("really important function ")} /* This code will be stripped */ } Result of the stripping is: var test = function () { var c = "!="; if ( !l.match.PSEUDO.test(c) && !/!=/.test(c)) { alert("/something bad will happen * } My idea is to modify the stripper to recognize the regular expression that way. diff --git a/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java b/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java index d31ae36..10b1aa6 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java @@ -130,7 +130,7 @@ public class JavaScriptStripper continue; } if (tmp == '=' || tmp == '(' || tmp == '{' || tmp == ':' || tmp == ',' || - tmp == '[' || tmp == ';') + tmp == '[' || tmp == ';' || tmp == '!') { state = REG_EXP; break; was (Author: rabam): Hi there, we also experienced this problem with Wicket 1.4.15. We found out that the JavascriptStripper did not recognize the regular expression in the booleasn expression (xx && !/!=/) which is used in jquery-1.5.1. Actually the regular expression is recognized at the second slash. Therefore the parsing breaks because the regex is not terminated correctly and ugly things happen (like the expression getting terminated by "*/*". A much more shorter example would be: var test = function () { var c = "!="; /* from jquery 1.5.1 */ if ( !l.match.PSEUDO.test(c) && !/!=/.test(c)) { alert("/something bad will happen */* "); } var importantFunction = function () {alert("really important function ")} /* This code will be stripped */ } Result of the stripping is: var test = function () { var c = "!="; if ( !l.match.PSEUDO.test(c) && !/!=/.test(c)) { alert("/something bad will happen * } My idea is to modify the stripper to recognize the regular expression that way. diff --git a/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java b/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java index d31ae36..10b1aa6 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/string/JavaScriptStripper.java @@ -130,7 +130,7 @@ public class JavaScriptStripper continue; } if (tmp == '=' || tmp == '(' || tmp == '{' || tmp == ':' || tmp == ',' || - tmp == '[' || tmp == ';') + tmp == '[' || tmp == ';' || tmp == '!') { state = REG_EXP; break; > DefaultJavascriptCompressor broken jquery v1.5.1 minified file > -------------------------------------------------------------- > > Key: WICKET-3519 > URL: https://issues.apache.org/jira/browse/WICKET-3519 > Project: Wicket > Issue Type: Bug > Components: wicket-core > Affects Versions: 1.4.16 > Environment: windows 7 x64 > Reporter: Olivier Dutrieux > Labels: javascript, jquery, wicket > Attachments: jquery-1.5.1.min.js > > > Hello, > The DefaultJavascriptCompressor broken jquery v1.5.1 Minified file: > text/javascript","*":"*/*"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* > text":a.String,"text html":!0,"text json":d.parseJSON,"text > xml":d.parseXML}},ajaxPrefilter:bM(bH),ajaxTransport:bM(bI),ajax:function(a,c){function > > v(a,c,l,n){if(r!==2){r=2,p&&clearTimeout(p),o=b,m=n||"",u.readyState=a?4:0;var > > q,t,v,w=l?bP(e,u,l):b,x,y;if(a>=200&&a<300||a===304){if(e.ifModified){if(x=u.getResponseHeader("Last-Modified"))d.lastModified[k]=x;if(y=u.getResponseHeader("Etag"))d.etag[k]=y}if(a===304)c="notmodified",q=!0;else > > try{t=bQ(e,w),c="success",q=!0}catch(z){c="parsererror",v=z}}else{v=c;if(!c||a)c="error",a<0&&(a=0)}u.status=a,u.statusText=c,q?h.resolveWith(f,[t,c,u]):h.rejectWith(f,[u,c,v]),u.statusCode(j),j=b,s&&g.trigger("ajax"+(q?"Success":"Error"),[u,e,q?t:v]),i.resolveWith(f,[u,c]),s&&(g.trigger("ajaxComplete",[u,e]),--d.active||d.event.trigger("ajaxStop"))}}typeof > a==="object"&&(c=a,a=b),c=c||{};var > e=d.ajaxSetup({},c),f=e.context||e,g=f!==e&&(f.nodeType||f instanceof > d)?d(f):d.event,h=d.Deferred(),i=d._Deferred(),j=e.statusCode||{},k,l={},m,n,o,p,q,r=0,s,t,u={readyState:0,setRequestHeader:function(a,b){r||(l[a.toLowerCase().replace(bD,bE)]=b);return > this},getAllResponseHeaders:function(){return > r===2?m:null},getResponseHeader:function(a){var > c;if(r===2){if(!n){n={};while(c=bt.exec(m))n[c[1].toLowerCase()]=c[2]}c=n[a.toLowerCase()]}return > c===b?null:c},overrideMimeType:function(a){r||(e.mimeType=a);return > this},abort:function(a){a=a||"abort",o&&o.abort(a),v(0,a);return > this}};h.promise(u),u.success=u.done,u.error=u.fail,u.complete=i.done,u.statusCode=function(a){if(a){var > b;if(r<2)for(b in a)j[b]=[j[b],a[b]];else b=a[u.status],u.then(b,b)}return > this},e.url=((a||e.url)+"").replace(bs,"").replace(bx,bK[1]+"//"),e.dataTypes=d.trim(e.dataType||"*").toLowerCase().split(bB),e.crossDomain||(q=bF.exec(e.url.toLowerCase()),e.crossDomain=q&&(q[1]!=bK[1]||q[2]!=bK[2]||(q[3]||(q[1]==="http:"?80:443))!=(bK[3]||(bK[1]==="http:"?80:443)))),e.data&&e.processData&&typeof > > e.data!=="string"&&(e.data=d.param(e.data,e.traditional)),bN(bH,e,c,u);if(r===2)return!1;s=e.global,e.type=e.type.toUpperCase(),e.hasContent=!bw.test(e.type),s&&d.active++===0&&d.event.trigger("ajaxStart");if(!e.hasContent){e.data&&(e.url+=(by.test(e.url)?"&":"?")+e.data),k=e.url;if(e.cache===!1){var > > w=d.now(),x=e.url.replace(bC,"$1_="+w);e.url=x+(x===e.url?(by.test(e.url)?"&":"?")+"_="+w:"")}}if(e.data&&e.hasContent&&e.contentType!==!1||c.contentType)l["Content-Type"]=e.contentType;e.ifModified&&(k=k||e.url,d.lastModified[k]&&(l["If-Modified-Since"]=d.lastModified[k]),d.etag[k]&&(l["If-None-Match"]=d.etag[k])),l.Accept=e.dataTypes[0]&&e.accepts[e.dataTypes[0]]?e.accepts[e.dataTypes[0]]+(e.dataTypes[0]!=="*"?", > */*; q=0.01":"") > become : > text/javascript","*":"**; q=0.01":"") > I think is due to the /* ... */ on the javascript file and is interpreted by > stripCommentsAndWhitespace as a comment. > Best regards -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira