]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/Tests: Verify unsupported UTF-8 data is rejected
authorJordan Justen <jordan.l.justen@intel.com>
Tue, 23 Jun 2015 23:34:38 +0000 (23:34 +0000)
committerjljusten <jljusten@Edk2>
Tue, 23 Jun 2015 23:34:38 +0000 (23:34 +0000)
Surrogate pair characters can be encoded in UTF-8 files, but they are
not valid UCS-2 characters.

For example, this python interpreter code:
>>> import codecs
>>> codecs.encode(u'\ud801', 'utf-8')
'\xed\xa0\x81'

But, the range of 0xd800 - 0xdfff should be rejected as unicode code
points because they are reserved for the surrogate pair usage in
UTF-16 files.

We test that this case is rejected for UTF-8 with and without the
UTF-8 BOM.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Yingke Liu <yingke.d.liu@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17698 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Tests/CheckUnicodeSourceFiles.py

index 102dc3c1f9cdd521e7fdaeaf43681862a63a1b16..2eeb0f551d7e1d5fa6d3094e11a6b70ecb339c59 100644 (file)
@@ -139,6 +139,30 @@ class Tests(TestTools.BaseToolsTest):
 \r
         self.CheckFile('utf_8', shouldPass=False, string=data)\r
 \r
+    def testSurrogatePairUnicodeCharInUtf8File(self):\r
+        #\r
+        # Surrogate Pair code points are used in UTF-16 files to\r
+        # encode the Supplementary Plane characters. In UTF-8, it is\r
+        # trivial to encode these code points, but they are not valid\r
+        # code points for characters, since they are reserved for the\r
+        # UTF-16 Surrogate Pairs.\r
+        #\r
+        # This test makes sure that BaseTools rejects these characters\r
+        # if seen in a .uni file.\r
+        #\r
+        data = '\xed\xa0\x81'\r
+\r
+        self.CheckFile(encoding=None, shouldPass=False, string=data)\r
+\r
+    def testSurrogatePairUnicodeCharInUtf8FileWithBom(self):\r
+        #\r
+        # Same test as testSurrogatePairUnicodeCharInUtf8File, but add\r
+        # the UTF-8 BOM\r
+        #\r
+        data = codecs.BOM_UTF8 + '\xed\xa0\x81'\r
+\r
+        self.CheckFile(encoding=None, shouldPass=False, string=data)\r
+\r
 TheTestSuite = TestTools.MakeTheTestSuite(locals())\r
 \r
 if __name__ == '__main__':\r