Skip to content

Commit

Permalink
FIX: localization of outgoing URIs in JS corrupts response (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
turquoiseowl committed Jul 10, 2018
1 parent c82d747 commit d085eb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/i18n.Tests/Tests/ResponseFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public void ResponseFilter_can_patch_html_urls()
Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"http://example.com/content/fred.txt\"></img>", "<img src=\"http://example.com/fr/content/fred.txt\"></img>" , "http://example.com/blog/");
Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"http://other.com/content/fred.txt\"></img>" , "<img src=\"http://other.com/content/fred.txt\"></img>" , "http://example.com/blog/"); // NB: foreign site so no langtag added

// One attribute - empty url
Helper_ResponseFilter_can_patch_html_urls(
"fr",
"<a href=\"\"></a>",
"<a href=\"\"></a>");

// One attribute.
Helper_ResponseFilter_can_patch_html_urls(
"fr",
Expand Down Expand Up @@ -396,6 +402,22 @@ public void ResponseFilter_can_patch_html_urls()
"fr",
string.Format("<script src=\"{0}https://example.com/fr/123\"></script>", EarlyUrlLocalizer.IgnoreLocalizationUrlPrefix),
"<script src=\"https://example.com/fr/123\"></script>");


string strMultilineScriptWithHref = @"<script>
try {
this._baseHref="""";
}
catch (e) {
}
</script>
<div class=""page_style_a"">";

Helper_ResponseFilter_can_patch_html_urls(
"fr",
strMultilineScriptWithHref,
strMultilineScriptWithHref);

}
}
}
2 changes: 1 addition & 1 deletion src/i18n/Concrete/EarlyUrlLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public string ProcessOutgoing(
/// Regex for finding and replacing urls in html.
/// </summary>
public static Regex m_regexHtmlUrls = new Regex(
"(?<pre><(?:script|img|a|area|link|base|input|frame|iframe|form)\\b.*?(?:src|href|action)\\s*=\\s*[\"']\\s*)(?<url>.+?)(?<post>\\s*[\"'][^>]*?>)",
"(?<pre><(?:script|img|a|area|link|base|input|frame|iframe|form)\\b[^>]*?\\b(?:src|href|action)\\s*=\\s*[\"']\\s*)(?<url>.+?)(?<post>\\s*[\"'][^>]*?>)",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
// The above supports most common ways for a URI to appear in HTML/XHTML.
// Note that if we fail to catch a URL here, it is not fatal; it only means we don't avoid a redirect
Expand Down

0 comments on commit d085eb2

Please sign in to comment.