| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -313,6 +313,17 @@ def test_load_source(self): | |||
| 313 | 313 | with self.assertRaisesRegex(ValueError, 'embedded null'): | |
| 314 | 314 | imp.load_source(__name__, __file__ + "\0") | |
| 315 | 315 | ||
| 316 | + @support.cpython_only | ||
| 317 | + def test_issue31315(self): | ||
| 318 | + # There shouldn't be an assertion failure in imp.create_dynamic(), | ||
| 319 | + # when spec.name is not a string. | ||
| 320 | + create_dynamic = support.get_attribute(imp, 'create_dynamic') | ||
| 321 | + class BadSpec: | ||
| 322 | + name = None | ||
| 323 | + origin = 'foo' | ||
| 324 | + with self.assertRaises(TypeError): | ||
| 325 | + create_dynamic(BadSpec()) | ||
| 326 | + | ||
| 316 | 327 | ||
| 317 | 328 | class ReloadTests(unittest.TestCase): | |
| 318 | 329 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix an assertion failure in imp.create_dynamic(), when spec.name is not a | ||
| 2 | + string. Patch by Oren Milman. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,6 +103,11 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) | |||
| 103 | 103 | if (name_unicode == NULL) { | |
| 104 | 104 | return NULL; | |
| 105 | 105 | } | |
| 106 | + if (!PyUnicode_Check(name_unicode)) { | ||
| 107 | + PyErr_SetString(PyExc_TypeError, | ||
| 108 | + "spec.name must be a string"); | ||
| 109 | + goto error; | ||
| 110 | + } | ||
| 106 | 111 | ||
| 107 | 112 | name = get_encoded_name(name_unicode, &hook_prefix); | |
| 108 | 113 | if (name == NULL) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments