JComments joomla extension + specific port
Workmate ran into an issue this week where the JComments joomla extension wasn’t working for a host running on a port other than 80 or 443.
Too lazy to write much up in detail so I’m just going to basically post code and let it speak for itself.
First up, check the page source to see how JComments is set up:
jcomments = JComments.new(8,'somejunk','http://hostname:20080/resource_string');
Ok. So JComments is at least being passed the port. Cool. So now have a look at the JComments js and see what it’s doing with that correct URI.
The JComments.prototype init function:
init: function(oi,og,r){var ua=navigator.userAgent.toLowerCase();this.browser={safari: /webkit/.test(ua),opera: /opera/.test(ua),msie: /msie/.test(ua) && !(/opera/.test(ua)),mozilla: /mozilla/.test(ua) && !(/(compatible|webkit)/.test(ua))};this.oi=oi;this.og=og;this.busy=new JCommentsIndicator();
var h=location.hostname,d,i1,i2;i1=r.indexOf('://');if(i1!=-1){i2=r.indexOf('/',i1+3);if(i2!=-1){d=r.substring(i1+3,i2);if(d!=h){r=r.replace(d,h);}}}this.requestURI=r;var th=this;jtajax.startLoading=function(){th.busy.show();};jtajax.finishLoading=function(){th.busy.hide();};},
Not entirely helpful in its raw form, but I can at least see some stuff about URI’s in there. Reformatted:
init: function(oi,og,r){
var ua=navigator.userAgent.toLowerCase();
this.browser={
safari: /webkit/.test(ua),opera: /opera/.test(ua),msie: /msie/.test(ua) && !(/opera/.test(ua)),mozilla: /mozilla/.test(ua) && !(/(compatible|webkit)/.test(ua))
};
this.oi=oi;this.og=og;this.busy=new JCommentsIndicator();
var h=location.hostname,d,i1,i2;
i1=r.indexOf('://');
if(i1!=-1){
i2=r.indexOf('/',i1+3);
if(i2!=-1){
d=r.substring(i1+3,i2);
if(d!=h){
r=r.replace(d,h);
}
}
}
this.requestURI=r;
var th=this;
jtajax.startLoading=function(){th.busy.show();};
jtajax.finishLoading=function(){th.busy.hide();};},
Ok so now I can at least see specific lines relating to the request URI and those not, so can cut down on the noise and relabel variables to help with understanding:
init: function(oi,og,request){
var browser_hostname=location.browser_hostname
var request_hostname,after_proto_declaration,end_of_browser_hostname;
after_proto_declaration=request.indexOf('://');
if(after_proto_declaration!=-1){
end_of_browser_hostname=request.indexOf('/',after_proto_declaration+3);
if(end_of_browser_hostname!=-1){
request_hostname=request.substring(after_proto_declaration+3,end_of_browser_hostname);
if(request_hostname!=browser_hostname){
request=request.replace(request_hostname,browser_hostname);
}
}
}
this.requestURI=request;
},
Ok, that makes heaps more sense, and now the problem is pretty obvious, end_of_hostname is determined by finding the first / after the start of the hostname rather than the first / or the first :. Which means that the port declaration is caught up in the replace later on where the request_hostname is replaced with the browser_hostname.