From 0d19d4913a051b6830b910b196ee146fd803ccb6 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Mon, 18 Dec 2006 22:53:13 +0000 Subject: [PATCH] =?UTF-8?q?D=C3=A9nonciation=20des=20ID=20d=C3=A9clar?= =?UTF-8?q?=C3=A9s=20plusieurs=20fois=20dans=20une=20meme=20page,=20sur=20?= =?UTF-8?q?la=20base=20du=20symbole=20ID=20indiqu=C3=A9=20dans=20la=20DTD?= =?UTF-8?q?=20comme=20type=20d'un=20attribut=20(en=20l'occurrence,=20uniqu?= =?UTF-8?q?ement=20"id").?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les seules différences avec la validation officielle résident donc dans quelques successions pathologiques non signalées, comme Body avant Head et autre improbabilités. De toutes façons, quand on lit dans les DTD de xhtml (meme la stricte: thttp://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd): {{{ <!-- Each label must not contain more than ONE field Label elements shouldn't be nested. --> <!ELEMENT label %Inline;> <!ATTLIST label %attrs; for IDREF #IMPLIED accesskey %Character; #IMPLIED onfocus %Script; #IMPLIED onblur %Script; #IMPLIED > }}} on se dit que l'officiel n'est pas un gage de sérieux, et leur validateur se garde bien de corriger la paresse de la spécification par une implémentation respectant le commentaire, puisqu'il considère ceci comme valide: {{{ <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd' ><html lang='fr' dir='ltr'> <head> <title></title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </head> <body> <p id='x'><label for='x'><label> <input /> label+label=les moches <input /> </label></label></p> </body> </html> }}} ''Note: The Validator XML support has some limitations.'': oui, et ses grammaires aussi... --- ecrire/inc/sax.php | 1 + ecrire/inc/validateur.php | 44 ++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/ecrire/inc/sax.php b/ecrire/inc/sax.php index a8cbd81933..ba7359d573 100644 --- a/ecrire/inc/sax.php +++ b/ecrire/inc/sax.php @@ -181,6 +181,7 @@ function xml_parsestring($xml_parser, $data) var $elements = array(); var $entites = array(); var $attributs = array(); + var $ids = array(); var $err = array(); } diff --git a/ecrire/inc/validateur.php b/ecrire/inc/validateur.php index 4a9623c371..11ded21c14 100644 --- a/ecrire/inc/validateur.php +++ b/ecrire/inc/validateur.php @@ -71,7 +71,7 @@ function inc_validateur_dist($data) $att = array(); if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+(\S+)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { foreach($r2 as $m2) { - $v = preg_match('/^\w+$/', $m2[2]) ? '' + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); $att[$m2[1]] = array($v, $m2[5]); } @@ -146,17 +146,37 @@ function validerAttribut($parser, $name, $val, $bal) . _L(' attribut inconnu de ') . "<b>$bal</b>" . coordonnees_erreur($parser); - elseif ($a[$name][0][0]=='/') { - if (!preg_match($a[$name][0], $val)) { - $phraseur_xml->err[]= " <p><b>$val</b>" - . _L(" valeur de l'attribut ") - . "<b>$name</b>" - . _L(' de ') - . "<b>$bal</b>" - . _L(" n'est pas conforme au motif</p><p>") - . "<b>" . $a[$name][0] . "</b></p>" - . coordonnees_erreur($parser); - } + else{ + $type = $a[$name][0]; + if ($type[0]=='/') { + if (!preg_match($a[$name][0], $val)) { + $phraseur_xml->err[]= " <p><b>$val</b>" + . _L(" valeur de l'attribut ") + . "<b>$name</b>" + . _L(' de ') + . "<b>$bal</b>" + . _L(" n'est pas conforme au motif</p><p>") + . "<b>" . $a[$name][0] . "</b></p>" + . coordonnees_erreur($parser); + } + } elseif ($type == 'ID') { + if (isset($phraseur_xml->ids[$val])) { + $phraseur_xml->err[]= " <p><b>$val</b>" + . _L(" valeur de l'attribut ") + . "<b>$name</b>" + . _L(' de ') + . "<b>$bal</b>" + . _L(" incorrect ") + . coordonnees_erreur($parser); + list($l,$c) = $phraseur_xml->ids[$val]; + $phraseur_xml->err[]= " <p><b>$val</b>" + . _L(" vu auparavant ligne ") + . $l + . _L(" colonne ") + . $c; + } + else $phraseur_xml->ids[$val] = array(xml_get_current_line_number($parser), xml_get_current_column_number($parser)); + } } } ?> -- GitLab