-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Writer/Xls/Parser::advance Should Parse by Character
It currently parsed by byte, which is not a good thing in a UTF-8 system. See the discussion at the bottom of PR #4203. That turns out to not be the change which led to this problem; that would have been PR #4323. That change came about because using Composer/Pcre revealed bugs in several regular expressions used in Writer/Xls/Parser. This ticket comes about because more bugs were revealed in the same module. The problem is that the `advance` method needs to process formulas character by character, but is instead doing it byte by byte. It is changed to advance by characters, and tests for non-ASCII characters are added.
- Loading branch information
Showing
3 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tests/PhpSpreadsheetTests/Writer/Xls/NonLatinFormulasTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xls; | ||
|
||
use PhpOffice\PhpSpreadsheet\Cell\DataValidation; | ||
use PhpOffice\PhpSpreadsheet\Cell\DataValidator; | ||
use PhpOffice\PhpSpreadsheet\NamedRange; | ||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; | ||
|
||
class NonLatinFormulasTest extends AbstractFunctional | ||
{ | ||
public function testNonLatin(): void | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
$worksheet = $spreadsheet->getActiveSheet(); | ||
|
||
$validation = $worksheet->getCell('B1')->getDataValidation(); | ||
$validation->setType(DataValidation::TYPE_LIST); | ||
$validation->setErrorStyle(DataValidation::STYLE_STOP); | ||
$validation->setAllowBlank(false); | ||
$validation->setShowInputMessage(true); | ||
$validation->setShowErrorMessage(true); | ||
$validation->setShowDropDown(true); | ||
$validation->setFormula1('"слово, сло"'); | ||
|
||
$dataValidator = new DataValidator(); | ||
$worksheet->getCell('B1')->setValue('слово'); | ||
self::assertTrue( | ||
$dataValidator->isValid($worksheet->getCell('B1')) | ||
); | ||
$worksheet->getCell('B1')->setValue('слов'); | ||
self::assertFalse( | ||
$dataValidator->isValid($worksheet->getCell('B1')) | ||
); | ||
|
||
$worksheet->setTitle('словслов'); | ||
$worksheet->getCell('A1')->setValue('=словслов!B1'); | ||
$worksheet->getCell('A2')->setValue("='словслов'!B1"); | ||
$spreadsheet->addNamedRange(new NamedRange('слсл', $worksheet, '$B$1')); | ||
$worksheet->getCell('A3')->setValue('=слсл'); | ||
|
||
$robj = $this->writeAndReload($spreadsheet, 'Xls'); | ||
$spreadsheet->disconnectWorksheets(); | ||
$sheet0 = $robj->getActiveSheet(); | ||
self::assertSame('словслов', $sheet0->getTitle()); | ||
self::assertSame('=словслов!B1', $sheet0->getCell('A1')->getValue()); | ||
self::assertSame('слов', $sheet0->getCell('A1')->getCalculatedValue()); | ||
// Quotes around sheet name are stripped off - harmless | ||
//self::assertSame("='словслов'!B1", $sheet0->getCell('A2')->getValue()); | ||
self::assertSame('слов', $sheet0->getCell('A2')->getCalculatedValue()); | ||
// Formulas with defined names don't work in Xls Writer | ||
//self::assertSame('=слсл', $sheet0->getCell('A3')->getValue()); | ||
// But result should be accurate | ||
self::assertSame('слов', $sheet0->getCell('A3')->getCalculatedValue()); | ||
$names = $robj->getDefinedNames(); | ||
self::assertCount(1, $names); | ||
// name has been uppercased | ||
$namedRange = $names['СЛСЛ'] ?? null; | ||
self::assertInstanceOf(NamedRange::class, $namedRange); | ||
self::assertSame('$B$1', $namedRange->getRange()); | ||
|
||
$robj->disconnectWorksheets(); | ||
} | ||
} |