色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

asp.NET開發(fā)中正則表達式中BUG分析

比如以下的代碼就是用來測試用正則表達式匹配從 0xff 到 0xffff 的字符。而值范圍在 0 到 0xfe 的所有字符是不能被匹配的。  
以下為引用的內(nèi)容:
復制代碼 代碼如下:
Regex regex = new Regex(@"[/u00FF-/uFFFF]+");
  // The characters, whoes value are smaller than 0xff,
  // are not expected to be matched.
  for (int i = 0; i <0xff; i++) {
  string s = new string(new char[] { (char)i });
  Debug.Assert(!regex.IsMatch(s), string.Format(
  "The character was not expected to be matched: 0x{0:X}!", i));
  }
  // However, the characters whoes value
  // are greater than 0xfe are expected to be matched.
  for (int i = 0xff; i <= 0xffff; i++) {
  string s = new string(new char[] { (char)i });
  Debug.Assert(regex.IsMatch(s), string.Format(
  "The character was expected to be matched: 0x{0:X}!", i));
  }

這時的運行結(jié)果是正常的,沒有任何的斷言錯誤出現(xiàn)。
然而當使用忽略大小寫的匹配模式時,結(jié)果就不一樣了。將上面代碼中的第一行改成:
1Regex regex = new Regex(@"[/u00FF-/uFFFF]+", RegexOptions.IgnoreCase);
程序運行的時候就會有兩處斷言錯誤。它們分別是字符值為 73 和 105,也就是小寫字母 i 和大寫字母 I。 這個 bug 非常奇怪,別的字符都很正常!而且用 Javascript腳本在 IE (版本是6.0)里面運行也同樣有這么 bug 存在(比如下面這段代碼)。然而在 Firefox中運行就是沒有問題的。還是 Firefox 好啊,呵呵!
以下為引用的內(nèi)容:
復制代碼 代碼如下:
var re = /[/u00FF-/uFFFF]+/;
  // var re = /[/u00FF-/uFFFF]+/i;
  for(var i=0; i<0xff; i++) {
  var s = String.fromCharCode( i );
  if ( re.test(s) ) {
  alert( 'Should not be matched: ' + i + '!' );
  }
  }
  for(var i=0xff; i<=0xffff; i++) {
  var s = String.fromCharCode( i );
  if ( !re.test(s) ) {
  alert( 'Should be matched: ' + i + '!' );
  }
  }

AspNet技術(shù)asp.NET開發(fā)中正則表達式中BUG分析,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 宁海县| 安岳县| 长泰县| 安远县| 万载县| 万荣县| 鹿邑县| 双鸭山市| 唐海县| 芮城县| 高雄市| 共和县| 南召县| 襄垣县| 同仁县| 内黄县| 酒泉市| 古蔺县| 延川县| 南京市| 永丰县| 武隆县| 托里县| 恭城| 怀仁县| 老河口市| 阆中市| 财经| 阆中市| 来安县| 东至县| 贵州省| 永福县| 林口县| 定日县| 年辖:市辖区| 上饶市| 廊坊市| 顺昌县| 广汉市| 蓬安县|