PHP_XLSXWriter icon indicating copy to clipboard operation
PHP_XLSXWriter copied to clipboard

BUG: Sheetname loses leading/trailing spaces (which is valid)

Open AzzaAzza69 opened this issue 4 years ago • 0 comments

While a sheetname can't start or end with a single quote ('), spaces are allowed, so the sanitize_sheetname function should be:

public static function sanitize_sheetname($sheetname)
{
		static $badchars  = '\\/?*:[]';
//		static $goodchars = '        ';
//		$sheetname = strtr($sheetname, $badchars, $goodchars);
//		$sheetname = substr($sheetname, 0, 31);
//		$sheetname = trim(trim(trim($sheetname),"'"));//trim before and after trimming single quotes
//		return !empty($sheetname) ? $sheetname : 'Sheet'.((rand()%900)+100);

		static $goodchars = '       ';// looks shorter than badchars due to double backslash to indicate single character
		$sheetname = trim(substr(strtr($sheetname, $badchars, $goodchars),0,31),"'");	// sheetname can't start or end with single quotes
		return !empty(trim($sheetname)) ? $sheetname : 'Sheet'.((rand()%900)+100);	// keep leading/trailing spaces
}

AzzaAzza69 avatar Oct 03 '20 09:10 AzzaAzza69