public void TestUnicodeMatch() { int m; m = PerlRegExp.Match ( new PhpBytes(Encoding.UTF8.GetBytes("/[ř]/u")), new PhpBytes(Encoding.UTF8.GetBytes("12ščř45")) ); Assert.AreEqual(m, 1); Encoding enc = Configuration.Application.Globalization.PageEncoding; m = PerlRegExp.Match ( new PhpBytes(enc.GetBytes("/[ř]/")), new PhpBytes("12ščř45") ); Assert.AreEqual(m, 1); // binary cache test: m = PerlRegExp.Match ( new PhpBytes(enc.GetBytes("/[ř]/")), new PhpBytes("12ščř45") ); Assert.AreEqual(m, 1); int count; object r = PerlRegExp.Replace ( ScriptContext.CurrentContext, null, null, new PhpBytes(Encoding.UTF8.GetBytes("/[řš]+/u")), "|žýř|", new PhpBytes(Encoding.UTF8.GetBytes("Hešovářřřříčkořš hxx")), 1000, out count ); Assert.AreEqual(r as string, "He|žýř|ová|žýř|íčko|žýř| hxx"); Assert.AreEqual(count, 3); }
public static object filter_var(object variable, int filter /*= FILTER_DEFAULT*/, object options) { switch (filter) { // // SANITIZE // case (int)FilterSanitize.FILTER_DEFAULT: return(Core.Convert.ObjectToString(variable)); case (int)FilterSanitize.EMAIL: // Remove all characters except letters, digits and !#$%&'*+-/=?^_`{|}~@.[]. return(FilterSanitizeString(PHP.Core.Convert.ObjectToString(variable), (c) => (int)c <= 0x7f && (Char.IsLetterOrDigit(c) || c == '!' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' || c == '*' || c == '+' || c == '-' || c == '/' || c == '=' || c == '!' || c == '?' || c == '^' || c == '_' || c == '`' || c == '{' || c == '|' || c == '}' || c == '~' || c == '@' || c == '.' || c == '[' || c == ']'))); // // VALIDATE // case (int)FilterValidate.EMAIL: { var str = PHP.Core.Convert.ObjectToString(variable); return(RegexUtilities.IsValidEmail(str) ? str : (object)false); } case (int)FilterValidate.INT: { int result; if (int.TryParse((PhpVariable.AsString(variable) ?? string.Empty).Trim(), out result)) { if (options != null) { PhpException.ArgumentValueNotSupported("options", "!null"); } return(result); // TODO: options: min_range, max_range } else { return(false); } } case (int)FilterValidate.REGEXP: { PhpArray optarray; // options = options['options']['regexp'] if ((optarray = PhpArray.AsPhpArray(options)) != null && optarray.TryGetValue("options", out options) && (optarray = PhpArray.AsPhpArray(options)) != null && optarray.TryGetValue("regexp", out options)) { if (PerlRegExp.Match(options, variable) > 0) { return(variable); } } else { PhpException.InvalidArgument("options", LibResources.GetString("option_missing", "regexp")); } return(false); } default: PhpException.ArgumentValueNotSupported("filter", filter); break; } return(false); }