Skip to content

Commit

Permalink
Fix PCD parsing for PCDs that have a single quote in them (#600)
Browse files Browse the repository at this point in the history
The PCD parsing regex pattern failed for PCDs that had a single quote

For example, 
gEfiMdePkgTokenSpaceGuid.PcdSingleQuote|"eng'fraengfra"|VOID*|0x0000002f
CRITICAL - EXCEPTION: Too few parts: ['PcdSingleQuote|"eng\'fraengfra"', 'VOID*', '0x0000002f']

The new pattern should allow the usage of single quotes

Co-authored-by: Nishanth1311 <[email protected]>
  • Loading branch information
NishanthSanjeevi and Nishanth1311 authored Jul 25, 2024
1 parent b9856f3 commit 60c64b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion edk2toollib/uefi/edk2/parsers/dec_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _parse(self, rawtext: str) -> None:
self.token_space_name = sp[0].strip()

# Regular expression pattern to match the symbol '|' that is not inside quotes
pattern = r'\|(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)'
pattern = r'\|(?=(?:(?:[^\'"]*(?:\'[^\']*\'|"[^"]*"))*[^\'"]*)$)'
op = re.split(pattern, sp[2])

# if it's 2 long, we need to check that it's a structured PCD
Expand Down
9 changes: 9 additions & 0 deletions tests.unit/parsers/test_dec_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ def test_string_containing_a_pipe(self):
self.assertEqual(a.type, "VOID*")
self.assertEqual(a.id, "0x00010001")

def test_string_containing_single_quote(self):
SAMPLE_DATA_DECL = """gTestTokenSpaceGuid.PcdTestString|"eng'fraengfra"|VOID*|0x00010001"""
a = PcdDeclarationEntry("testpkg", SAMPLE_DATA_DECL)
self.assertEqual(a.token_space_name, "gTestTokenSpaceGuid")
self.assertEqual(a.name, "PcdTestString")
self.assertEqual(a.default_value, "\"eng'fraengfra\"")
self.assertEqual(a.type, "VOID*")
self.assertEqual(a.id, "0x00010001")

class TestDecParser(unittest.TestCase):

SAMPLE_DEC_FILE = \
Expand Down

0 comments on commit 60c64b0

Please sign in to comment.