From 4fde66f28dd0dc20cf0e4ecbe8e56a0419a91ce5 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 5 Jan 2009 15:59:35 +0000 Subject: [PATCH] Refactor somewhat so that escapeId() works right r45267 commented out the logic prohibiting numbers and so on at the start of id's. I've uncommented this logic, but passed 'noninitial' as an option to escapeId() in all necessary circumstances. Shouldn't change behavior, this is to simplify some further work I'm about to do. --- includes/Sanitizer.php | 9 +-------- includes/Title.php | 2 +- includes/parser/Parser.php | 4 ++-- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index e89633f22f..a433ce0029 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -620,7 +620,7 @@ class Sanitizer { if ( $attribute === 'id' ) { global $wgEnforceHtmlIds; $value = Sanitizer::escapeId( $value, - $wgEnforceHtmlIds ? array() : 'xml' ); + $wgEnforceHtmlIds ? 'noninitial' : 'xml' ); } // If this attribute was previously set, override it. @@ -806,18 +806,11 @@ class Sanitizer { $id = urlencode( Sanitizer::decodeCharReferences( strtr( $id, ' ', '_' ) ) ); $id = str_replace( array_keys( $replace ), array_values( $replace ), $id ); - /* - // Let's not go changing our links just yet, since we plan to - // rip this out anyway and switch to the prettier Unicode-friendly - // links as XHTML and HTML 5 allow and browsers seem to think is - // just a-ok to do. - // if ( !preg_match( '/^[a-zA-Z]/', $id ) && !in_array( 'noninitial', $options ) ) { // Initial character must be a letter! $id = "x$id"; } - */ return $id; } diff --git a/includes/Title.php b/includes/Title.php index 9fd4c79c85..d41485cd2e 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -457,7 +457,7 @@ class Title { # one version of Opera 9.x. The W3C validator, for one, doesn't seem # to care if they aren't encoded. return Sanitizer::escapeId( $fragment, - $wgEnforceHtmlIds ? array() : 'xml' ); + $wgEnforceHtmlIds ? 'noninitial' : 'xml' ); } #---------------------------------------------------------------------------- diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index a5adc7e9b7..11cbc11d5c 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3618,7 +3618,7 @@ class Parser # Save headline for section edit hint before it's escaped $headlineHint = $safeHeadline; $safeHeadline = Sanitizer::escapeId( $safeHeadline, - $wgEnforceHtmlIds ? array() : 'xml' ); + $wgEnforceHtmlIds ? 'noninitial' : 'xml' ); # HTML names must be case-insensitively unique (bug 10721) $arrayKey = strtolower( $safeHeadline ); @@ -4688,7 +4688,7 @@ class Parser # Strip out wikitext links(they break the anchor) $text = $this->stripSectionName( $text ); return '#' . Sanitizer::escapeId( $text, - $wgEnforceHtmlIds ? array() : 'xml' ); + $wgEnforceHtmlIds ? 'noninitial' : 'xml' ); } /** -- 2.20.1