Skip to content

Commit

Permalink
Don't bomb when query string is too long
Browse files Browse the repository at this point in the history
  • Loading branch information
lonekorean committed Nov 12, 2016
1 parent 006e9e4 commit f20755c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Website/Tester.aspx.cs
Expand Up @@ -26,6 +26,7 @@ public partial class Tester : PageBase
private const string MATCH_HIGHLIGHT_LEFT_MARKER = "(--##REGEXSTORM:LEFT##--)";
private const string MATCH_HIGHLIGHT_RIGHT_MARKER = "(--##REGEXSTORM:RIGHT##--)";
private const string EMPTY_START_MESSAGE = "Enter your <strong>pattern</strong> and <strong>input</strong> above to see the good stuff here.";
private const int MAX_URL_LENGTH = 2000;

#endregion

Expand Down Expand Up @@ -763,10 +764,20 @@ private string GetStateUrl()
url.Path = this.RawPath;

// set new query string
url.Query = queryString.ToString().TrimStart('&');

// return the full absolute url
return url.Uri.AbsoluteUri;
var finalQueryString = queryString.ToString().TrimStart('&');
var maxQueryStringLength = MAX_URL_LENGTH - url.Uri.AbsoluteUri.Length - 1; // -1 for the ?
if (finalQueryString.Length > maxQueryStringLength)
{
// crazy long query strings aren't handled well by browsers and can
// even cause exceptions with UriBuilder, so don't use them
return "(permalink is too long to generate)";
}
else
{
// return the full absolute url
url.Query = finalQueryString;
return url.Uri.AbsoluteUri;
}
}

private string MatchHighlightNoReplacements(Match m)
Expand Down

0 comments on commit f20755c

Please sign in to comment.