Skip to content

Commit ca4314a

Browse files
committed
Fix unicode encoding issues.
1 parent 369c548 commit ca4314a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Snippets.alfredworkflow

191 Bytes
Binary file not shown.

src/search.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$keywords = $argv[1];
4-
$doc = new DOMDocument;
4+
$doc = new DOMDocument('1.0', 'utf-8');
55

66
// this file has been serialized from Core Data (http://en.wikipedia.org/wiki/Core_Data).
77
$doc->load(getenv('HOME') . '/Library/Application Support/Snippets/Snippets.xml');
@@ -53,6 +53,11 @@
5353
$title .= ' (' . implode(', ', $tags) . ')';
5454
}
5555

56+
// decode Unicode escape sequences to proper UTF-8 encoded characters (like “\u3e00” to ">")
57+
$code = preg_replace_callback('/(\\\\+)u([0-9a-fA-F]{4})/u', function($match) {
58+
return $match[1] == '\\\\' ? $match[0] : mb_convert_encoding(pack('H*', $match[2]), 'UTF-8', 'UCS-2LE');
59+
}, $code);
60+
5661
// unescape slashes (they are escaped in the XML file)
5762
$code = str_replace('\\\\', '\\', $code);
5863

0 commit comments

Comments
 (0)