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

Skip to content

Commit 987403b

Browse files
committed
merge #11696
2 parents 79a9036 + f8d887e commit 987403b

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
@@ -172,9 +172,8 @@ def add_tables(db, module):
172172
add_data(db, table, getattr(module, table))
173173

174174
def make_id(str):
175-
#str = str.replace(".", "_") # colons are allowed
176-
for c in " -+~;":
177-
str = str.replace(c, "_")
175+
identifier_chars = string.ascii_letters + string.digits + "._"
176+
str = "".join([c if c in identifier_chars else "_" for c in str])
178177
if str[0] in (string.digits + "."):
179178
str = "_" + str
180179
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
@@ -570,6 +570,7 @@ Chris McDonough
570570
Greg McFarlane
571571
Alan McIntyre
572572
Michael McLay
573+
Mark Mc Mahon
573574
Gordon McMillan
574575
Caolan McNamara
575576
Andrew McNamara

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Core and Builtins
4949
Library
5050
-------
5151

52+
- Issue #11696: Fix ID generation in msilib.
53+
5254
- Issue #9696: Fix exception incorrectly raised by xdrlib.Packer.pack_int when
5355
trying to pack a negative (in-range) integer.
5456

0 commit comments

Comments
 (0)