mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Merge pull request #1266 from SchrodingersGat/barcode-data-fix
Limit barcode hash to printable characters.
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
				
			|||||||
# -*- coding: utf-8 -*-
 | 
					# -*- coding: utf-8 -*-
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import string
 | 
				
			||||||
import hashlib
 | 
					import hashlib
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -16,9 +17,18 @@ logger = logging.getLogger(__name__)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def hash_barcode(barcode_data):
 | 
					def hash_barcode(barcode_data):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Calculate an MD5 hash of barcode data
 | 
					    Calculate an MD5 hash of barcode data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    HACK: Remove any 'non printable' characters from the hash,
 | 
				
			||||||
 | 
					          as it seems browers will remove special control characters...
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    TODO: Work out a way around this!
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printable_chars = filter(lambda x: x in string.printable, barcode_data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    barcode_data = ''.join(list(printable_chars))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hash = hashlib.md5(str(barcode_data).encode())
 | 
					    hash = hashlib.md5(str(barcode_data).encode())
 | 
				
			||||||
    return str(hash.hexdigest())
 | 
					    return str(hash.hexdigest())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user