Skip to content

Commit

Permalink
Case folding support for environments without mbstring
Browse files Browse the repository at this point in the history
Per the spec, reference link matching is done by normalizing the label with a Unicode case fold, which mb_strtoupper provides.

But since not all systems have the relevant extension installed, we need to manually implement this logic by converting characters according to this table: http://www.unicode.org/Public/UNIDATA/CaseFolding.txt
  • Loading branch information
colinodell committed Dec 27, 2014
1 parent bbbd67c commit 6b28381
Show file tree
Hide file tree
Showing 3 changed files with 1,215 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Reference/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace League\CommonMark\Reference;

use League\CommonMark\Util\UnicodeCaseFolder;

/**
* Link reference
*/
Expand Down Expand Up @@ -87,6 +89,12 @@ public static function normalizeReference($string)
// leading/trailing whitespace
$string = preg_replace('/\s+/', '', trim($string));

// Convert to upper-case using Unicode case folding
// Use an alternate method if mb_strtoupper isn't available
if (!function_exists('mb_strtoupper')) {
return UnicodeCaseFolder::toUpperCase($string);
}

return mb_strtoupper($string, 'UTF-8');
}
}
Loading

0 comments on commit 6b28381

Please sign in to comment.