Erro de expressão regular do Internet Explorer 8 JScript
Estou testando no Internet Explorer 8 no Windows XP e encontrando um bug tedioso. Estou tentando testar seqüências de caracteres com uma expressão regular que funciona bem no firefox e bem testada independentemente no console ie8.
Mas quando através da minha função de fechamento a corda age estranhamente
[Editar] Código mais detalhado: Não é tão bom ou limpo quanto o snippet anterior.
var m_TableSorter = (function() {
// static reg expression string and array for ordering dates
var dateRegEx = new RegExp(
"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\s\\d{4}");
...
...
function greaterThan(left, right) {
window["globalLeft"] = left;
window["globalRight"] = right;
var a = $.trim(left.toLowerCase());
var b = $.trim(right.toLowerCase());
window["globalA"] = a.toString();
window["globalReg"] = dateRegEx;
if (dateRegEx.test(a) && dateRegEx.test(b)) {
var yearA = parseInt(a.substring(4,8), 10);
var yearB = parseInt(b.substring(4,8), 10);
if (yearA > yearB) {
return true;
} else if (yearB > yearA) {
return false;
} else {
/* ... */
var monthA =
$.inArray(a.substring(0,3).toUpperCase(), monthArray);
var monthB =
$.inArray(b.substring(0,3).toUpperCase(), monthArray);
m_Debug.tryAssert(monthA >= 0, "Date string malformed");
m_Debug.tryAssert(monthB >= 0, "Date string malformed");
if (monthA > monthB) {
return true;
} else {
return false;
}
}
}
//alert("NONDATE");
if ( a.toUpperCase() >= b.toUpperCase() ) {
return true;
}
return false;
}
function mergeArrays(pr_left, pr_right, pr_compareFunction, pr_rowIndex)
{
m_Debug.debugUtilityFunction(arguments);
var results = new Array();
var obj;
/* Merges in order so that if right > left then the results is
* [left right] otherwise the result is [right left] (Dependant on
* ascending or descending order)
*/
while (pr_left.length > 0 || pr_right.length > 0) {
if (pr_left.length > 0 && pr_right.length > 0) {
window["globalLeft1"] = $(pr_left[0].children[pr_rowIndex]).text().toString();
window["globalRight1"] = $(pr_right[0].children[pr_rowIndex]).text().toString();
var bool = pr_compareFunction(
$.trim($(pr_left[0].children[pr_rowIndex]).text()),
$.trim($(pr_right[0].children[pr_rowIndex]).text())
);
if (bool) {
results.push(pr_left.shift());
} else {
results.push(pr_right.shift());
}
} else if (pr_left.length > 0) {
for (obj in pr_left) {
results.push(pr_left[obj]);
}
break;
} else if (pr_right.length > 0) {
for (obj in pr_right) {
results.push(pr_right[obj]);
}
break;
}
}
return results;
}
Para omergeArrays
funçãopr_left
& pr_right
são lista jQuery de objetos TR. e estou comparando o texto nopr_rowIndex-th
célula da linha por duas linhas.
pr_compareFunction
é melhor que.
dateRegEx.test (a) retorna false porque a string a está com erros.
Testando no console ie8 me diz que
globalA.toLowerCase() == "sep 2010"
retorna falso. Nesse casoalert(globalA)
mostrou "set 2010" ealert(globalLeft)
mostrou "Sep 2010". Eu verifiquei .length em ambos para ser 8 como esperado.
globalLeft1 == globalLeft
parece ser verdade, mas também não são iguais às seqüências normais.
Não consigo entender por que o JScript não pode reconhecer essas duas strings. reproduzir essas etapas exatas no console funciona conforme o esperado.
[Editar mais]
A implementação diferente do javascript trata os caracteres de espaço sem quebra como uma classe de caracteres de espaço ou classe de caracteres que não são de espaço. Se isso é um bug ou se está funcionando como pretendido, está aberto a discussão.