Skip to content

Commit

Permalink
fix: replace content with port domain
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Jan 2, 2022
1 parent d1f3dfc commit cb4d222
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ func replaceHost(content, oldHost, newHost string, useSSL bool, proxyExternal bo
return s
}

if net.ParseIP(matchUrl.Hostname()) == nil {
if !hostNameRegexp.MatchString(matchUrl.Host) {
return s
}
// if host not a IP address or a valid domain name
if net.ParseIP(matchUrl.Hostname()) == nil && !hostNameRegexp.MatchString(matchUrl.Hostname()) {
return s
}

// overide url in query
Expand Down
9 changes: 9 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ var a=m;window.W_jd=window.W_jd||{};for(var b=0;b<a.length;b+=2)window.W_jd[a[b]
window.jsl=window.jsl||{};window.jsl.dh=function(d,e,c){try{var f=document.getElementById(d);if(f)f.innerHTML=e,c&&c();else{var a={id:d,script:String(!!c),milestone:String(google.jslm||0)};google.jsla&&(a.async=google.jsla);var g=document.createElement("div");g.innerHTML=e;var b=g.children[0];b&&(a.tag=b.tagName,a["class"]=String(b.className||null),a.name=String(b.getAttribute("jsname")));google.ml(Error("Missing ID."),!1,a)}}catch(h){google.ml(h,!0,{"jsl.dh":!0})}};(function(){var x=true;
google.jslm=x?2:1;})();google.x(null, function(){(function(){(function(){google.csct={};google.csct.ps='AOvVaw17ag9mz-2UL3tGGKniglcH\x26ust\x3d1641191845010685';})();})();(function(){(function(){google.csct.rw=true;})();})();(function(){(function(){google.csct.rl=true;})();})();(function(){google.drty&&google.drty(undefined,true);})();});google.drty&&google.drty(undefined,true);`,
},
{
name: "13",
args: args{
content: "https://example.com:8080/demo",
oldHost: "example.com:8080",
newHost: "localhost",
},
want: "http://localhost/demo",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit cb4d222

Please # to comment.