0

When a user inputs certain special characters i.e a html tag, the user receives this:

Error loading Partial View script (file: ~/Views/MacroPartials/ezSearch.cshtml)

I have been investigating and this seems to be a common issue and I attempted to apply a fix so it would strip out 'bad' characters:

public string CleanseSearchTerm(string input)
{
    System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9 -]");
    input = rgx.Replace(input, "");

    return input.ToString();
}

However, the issue is that this error is getting generated before it has a chance to hit my method to strip out 'bad' characters. Any ideas of how this can be resolved?

Kyle Eales
  • 41
  • 1
  • 6
  • Is examine returning the error or is a global configuration that triggers the "A potentially dangerous Request.Form value was detected " message? – Eyescream Jun 16 '21 at 15:21

2 Answers2

0

I haven't tried these changes myself Kyle but I have done some investigation to help you fix this problem. Could one of the following solutions help you?

See this Umbraco form question and its answers, especially the one from Ismail Mayat could help you.

Linked to Ismail's answer, there is also this "How to make the Lucene QueryParser more forgiving?" question and I'd recommend you to check the answers for this question, too.

Another answer that might help you is this stackoverflow answer.

Nurhak Kaya
  • 1,470
  • 1
  • 18
  • 20
0

Lucene.NET does contain a few classes to help with HTML stripping. These classes are located here in the Lucene.NET repo. Specifically, the HTMLStripCharFilter may be of interest.

RonC
  • 31,330
  • 19
  • 94
  • 139