Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8d887e

Browse files
committed
Closes #11696: Fix ID generation in msilib.
Patch by Mark Mc Mahon.
1 parent 92b60d5 commit f8d887e

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

Lib/msilib/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ def add_tables(db, module):
173173
add_data(db, table, getattr(module, table))
174174

175175
def make_id(str):
176-
#str = str.replace(".", "_") # colons are allowed
177-
for c in " -+~;":
178-
str = str.replace(c, "_")
176+
identifier_chars = string.ascii_letters + string.digits + "._"
177+
str = "".join([c if c in identifier_chars else "_" for c in str])
179178
if str[0] in (string.digits + "."):
180179
str = "_" + str
181180
assert re.match("^[A-Za-z_][A-Za-z0-9_.]*$", str), "FILE"+str

Lib/test/test_msilib.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
""" Test suite for the code in msilib """
2+
import unittest
3+
import os
4+
from test.support import run_unittest, import_module
5+
msilib = import_module('msilib')
6+
7+
class Test_make_id(unittest.TestCase):
8+
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
9+
"""The Identifier data type is a text string. Identifiers may contain the
10+
ASCII characters A-Z (a-z), digits, underscores (_), or periods (.).
11+
However, every identifier must begin with either a letter or an
12+
underscore.
13+
"""
14+
15+
def test_is_no_change_required(self):
16+
self.assertEqual(
17+
msilib.make_id("short"), "short")
18+
self.assertEqual(
19+
msilib.make_id("nochangerequired"), "nochangerequired")
20+
self.assertEqual(
21+
msilib.make_id("one.dot"), "one.dot")
22+
self.assertEqual(
23+
msilib.make_id("_"), "_")
24+
self.assertEqual(
25+
msilib.make_id("a"), "a")
26+
#self.assertEqual(
27+
# msilib.make_id(""), "")
28+
29+
def test_invalid_first_char(self):
30+
self.assertEqual(
31+
msilib.make_id("9.short"), "_9.short")
32+
self.assertEqual(
33+
msilib.make_id(".short"), "_.short")
34+
35+
def test_invalid_any_char(self):
36+
self.assertEqual(
37+
msilib.make_id(".s\x82ort"), "_.s_ort")
38+
self.assertEqual (
39+
msilib.make_id(".s\x82o?*+rt"), "_.s_o___rt")
40+
41+
42+
def test_main():
43+
run_unittest(__name__)
44+
45+
if __name__ == '__main__':
46+
test_main()

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ Chris McDonough
531531
Greg McFarlane
532532
Alan McIntyre
533533
Michael McLay
534+
Mark Mc Mahon
534535
Gordon McMillan
535536
Caolan McNamara
536537
Andrew McNamara

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #11696: Fix ID generation in msilib.
48+
4749
- Issue #9696: Fix exception incorrectly raised by xdrlib.Packer.pack_int when
4850
trying to pack a negative (in-range) integer.
4951

0 commit comments

Comments
 (0)