mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	The incremental decoder for utf-7 must preserve its state between calls.
Solves issue1460. Might not be a backport candidate: a new API function was added, and some code may rely on details in utf-7.py.
This commit is contained in:
		
							parent
							
								
									8c4592a77a
								
							
						
					
					
						commit
						5087980c1e
					
				
					 5 changed files with 61 additions and 23 deletions
				
			
		|  | @ -943,6 +943,14 @@ char utf7_special[128] = { | |||
| PyObject *PyUnicode_DecodeUTF7(const char *s, | ||||
| 			       Py_ssize_t size, | ||||
| 			       const char *errors) | ||||
| { | ||||
|     return PyUnicode_DecodeUTF7Stateful(s, size, errors, NULL); | ||||
| } | ||||
| 
 | ||||
| PyObject *PyUnicode_DecodeUTF7Stateful(const char *s, | ||||
| 			       Py_ssize_t size, | ||||
| 			       const char *errors, | ||||
| 			       Py_ssize_t *consumed) | ||||
| { | ||||
|     const char *starts = s; | ||||
|     Py_ssize_t startinpos; | ||||
|  | @ -962,8 +970,11 @@ PyObject *PyUnicode_DecodeUTF7(const char *s, | |||
|     unicode = _PyUnicode_New(size); | ||||
|     if (!unicode) | ||||
|         return NULL; | ||||
|     if (size == 0) | ||||
|     if (size == 0) { | ||||
|         if (consumed) | ||||
|             *consumed = 0; | ||||
|         return (PyObject *)unicode; | ||||
|     } | ||||
| 
 | ||||
|     p = unicode->str; | ||||
|     e = s + size; | ||||
|  | @ -1049,7 +1060,7 @@ PyObject *PyUnicode_DecodeUTF7(const char *s, | |||
|         goto onError; | ||||
|     } | ||||
| 
 | ||||
|     if (inShift) { | ||||
|     if (inShift && !consumed) { | ||||
|         outpos = p-PyUnicode_AS_UNICODE(unicode); | ||||
|         endinpos = size; | ||||
|         if (unicode_decode_call_errorhandler( | ||||
|  | @ -1061,6 +1072,12 @@ PyObject *PyUnicode_DecodeUTF7(const char *s, | |||
|         if (s < e) | ||||
|            goto restart; | ||||
|     } | ||||
|     if (consumed) { | ||||
|         if(inShift) | ||||
|             *consumed = startinpos; | ||||
|         else | ||||
|             *consumed = s-starts; | ||||
|     } | ||||
| 
 | ||||
|     if (_PyUnicode_Resize(&unicode, p - PyUnicode_AS_UNICODE(unicode)) < 0) | ||||
|         goto onError; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Amaury Forgeot d'Arc
						Amaury Forgeot d'Arc