1390 Commits

Author SHA1 Message Date
oleibman 1fdee23756 Update Mpdf (Php8.5 compatibility) r210 (#4593) 2025-08-21 13:42:56 -07:00
oleibman 81a0de2261 Breaking Change When Loading External Images
Images will be loaded from an external source (e.g. http://example.com/img.png) only if the reader is explicitly set to allow it via `$reader->setAllowExternalImages(true)`.
2025-08-02 18:33:29 -07:00
oleibman cfcbeaf4e4 All Readers - Allow or Forbid Fetching of External Images Release210 (#4546)
* All Readers - Allow or Forbid Fetching of External Images Release210

Add to all readers the option to allow or forbid fetching external images. This is unconditionally allowed now. The default will be set to "allow", so no code changes are necessary. However, we are giving consideration to changing the default.

* Update Changelog
2025-07-22 21:42:08 -07:00
oleibman 2219dedada Removing Columns/Rows Containing Merged Cells (#4472)
Backport PR #4465.
2025-05-15 22:02:25 -07:00
oleibman 126309f5e9 Allow Spreadsheet Serialization Branch release210 (#4406) 2025-03-14 07:37:33 -07:00
oleibman 99f5c18e51 Allow php-cs-fixer to Handle Implicit Backslashes 2025-02-10 22:20:43 -08:00
oleibman 12c2e79288 Fix TEXT and TIMEVALUE Functions 2.1 Branch (#4353)
Fix #4249. Technically speaking, only the 1.29 branch needs fixing, and only for TEXT. It was fixed for the other branches by PR #3898. However, in adding test cases for the fix, it became apparent that PhpSpreadsheet's parsing in TIMEVALUE (which is called from TEXT in the original issue) did not really match Excel's. There are probably still edge cases where it doesn't, but, in the absence of a spec for how it operates, this will do for now.

We do not usually backport fixes from the master branch. Because this is more of a forward port from the earlier branch, there is an equivalent PR for each active branch.
2025-02-10 20:46:55 -08:00
oleibman 3789837ca7 Backport 2 Fixes to Writer/Xls/Parser
PR #4333 and PR #4344.
2025-02-06 20:05:26 -08:00
oleibman f68f688810 Security Patch Special Characters in Protocol 2025-01-23 22:40:52 -08:00
oleibman 173ff7b936 Tweak One Test
Fluke failure in CI push.
2025-01-15 01:50:39 -08:00
oleibman 6e5bbcd045 Backported Security Patch 2025-01-11 19:19:56 -08:00
oleibman 3ebcbcf2cd Change hash code for worksheet branch release210 (#4307)
* Change hash code for worksheet branch release210

Backport of PR #4207

* Retitling Clone Worksheets

Backport of PR #4302.
2025-01-08 14:37:50 -08:00
oleibman 04e8b6edc1 Backport Html Writer Security Patches 2024-12-26 21:13:22 -08:00
oleibman 3df80f9a46 Restore Accidentally Disabled Test 2024-12-15 14:48:25 -08:00
oleibman 7327aa0d45 Upgrade Dompdf, Tcpdf, .gitattributes 2024-12-07 22:01:17 -08:00
oleibman 2dac558f34 Fix Minor Break Handling Drawings
Backport of #4241. Some security batches caused a minor break in Drawings, forcing `setWorksheet` to come after `setPath`. Although the problem is easily fixed in user code, this was not an intended change. Some slight recoding restores the earlier functionality where the order of calls was not important, without sacrificing the security gains.
2024-11-25 20:19:54 -08:00
oleibman 52de298ece Ignore Settings::libXmlLoaderOptions
Backport of PR #4233.
2024-11-21 22:17:24 -08:00
oleibman 819854a668 Upgrade PhpUnit
To a version which is aware that Php8.4 deprecates E_STRICT.
2024-11-14 12:08:33 -08:00
oleibman db89fe2b2b Simplify Test Bootstrap 2024-11-13 08:43:07 -08:00
oleibman 4545ecf648 Downgrade Symfony/Process
A bit messier than expected. Current version of symfony/process (used only in dev) has a security advisory. There is no version that can be upgraded to which supports Php8.0. However, a downgrade to V5 will work.

When running with Php8.4, PhpUnit references E_STRICT, which is deprecated in 8.4. I don't understand why this doesn't happen with release1291. Be that as it may, we can't upgrade Phpunit to V10 because we need to support Php8.0. So, monkey around with tests/bootstrap.php to avoid problems.
2024-11-12 19:23:20 -08:00
oleibman fbd9a63e2f Backport Security Patch 2024-11-10 01:29:56 -08:00
oleibman 2a1ece2ec0 Backport PR #4189 Csv Method 2024-10-14 21:53:35 -07:00
oleibman 60b115c312 Forgot to Delete Some Lines 2024-09-24 17:55:03 -07:00
oleibman c26e766130 Restore 2 Disabled Tests 2024-09-24 17:47:28 -07:00
oleibman e04ed222b3 Backport Security Patch 2024-09-24 05:55:56 -07:00
oleibman 392dd08c55 Html Writer Validate Hyperlink Protocols 2024-09-14 05:26:18 -07:00
oleibman a2448b197a More Tests 2024-09-13 10:18:23 -07:00
oleibman bc74f3aa1d Validate POST Data in Sample 45
Errors can result if not validated.
2024-09-08 15:40:25 -07:00
oleibman 949ff63e1f Prepare Csv Reader for Php8.4
Also security patches.
2024-09-08 11:53:27 -07:00
oleibman 4577f615c4 Merge branch 'master' into issue3995 2024-05-09 22:49:11 -07:00
oleibman d38b7cb35f Merge pull request #4016 from oleibman/stan9a
Better Definitions for Mixed Parameters and Values Part 1 of Many
2024-05-09 06:28:54 +00:00
oleibman b2befb4426 Correct Wrong-Case Directory Name 2024-05-06 16:50:02 -07:00
oleibman 09c9a310a0 Html Reader Non-UTF8 Charsets
Fix #3995. Fix #866. Fix #1681. Php DOM loadhtml defaults to character set ISO-8859-1, but our data is UTF-8. So Html Reader alters its html so that loadhtml will not misinterpret characters outside the ASCII range. This works for UTF-8, but breaks other charsets. However, loadhtml uses the correct non-default charset when charset is specified in a meta tag, or when the html starts with a BOM. So, it is sufficient for us to alter the non-ASCII characters only when (a) the data does not start with a BOM, and (b) there is no charset tag.

This will allow us to use:
- UTF-8 files or snippets without BOM, with or without charset
- UTF-8 files with BOM (charset should not be specified and will be ignored if it is)
- UTF-16 files with BOM (charset should not be specified and will be ignored if it is)
- all charsets which are ASCII-compatible for 0x00-0x7f when the charset is declared. This applies to ASCII itself, many Windows and Mac charsets, all of ISO-8859, and most CJK and other-language-specific charsets.

We cannot use:
- UTF-16BE or UTF-16LE declared in a meta tag
- UTF-32, with or without a BOM (browser recommendation is to not support UTF-32, and most browsers do not support it)
- unknown (to loadhtml) or non-ASCII-compatible charsets (EBCDIC?)

I will note that the way I detect the `charset` attribute is imperfect (e.g. might find it in text rather than a meta tag). I think we'd need to write a browser to get it perfect. Anyhow, it is about the same as XmlScanner's attempt to find the `encoding` attribute, and, if it's good enough there, it ought to be good enough here.
2024-05-06 16:43:23 -07:00
oleibman 8d5577a3c4 Improved Test for ConvertUOM
Scrutinizer balked at quotes around key 'Unit Name'; no reason not to use 'UnitName' instead.

Having done that, several ConvertUOM tests seemed a little unconvincing. Replaced them with improved versions.
2024-05-05 06:14:28 -07:00
oleibman 64f354eb6e Better Definitions for Mixed Parameters and Values Part 1 of Many
Improve documentation within program by making explicit what types of values are allowed for variables described as "mixed". In order to avoid broken functionality, this is done mainly through doc-blocks. This will get us closer to Phpstan Level 9, but many changes will be needed before we can consider that.

Executable code change is to add 2 new methods to Cell - `getValueString` and `getCalculatedValueString`, which are the same as the methods without the String suffix, except that they always return a string result. These are invoked at several places in the code where it makes sense, in particular by Writer code.
2024-05-05 04:37:46 -07:00
oleibman c56a58358e Merge pull request #4006 from oleibman/issue4004
RTL Text Alignment in Xlsx Comment
2024-05-05 11:17:55 +00:00
oleibman db602bde89 Merge branch 'master' into issue4001 2024-05-04 21:05:15 -07:00
oleibman 8485cd195f Merge pull request #4003 from oleibman/issue3999
Improvements to Xml Reader
2024-05-05 03:55:44 +00:00
oleibman d40a1cfa52 Xml Reader Rich Text
Fix #4001. Thanks to @SlowFox71 who reported the problem and developed most of the solution. This PR adds Rich Text support to the XML reader. The Xml Spreadsheet stores Rich Text as Html tags, children of the ss:Data tag using a specific namespace. These can be parsed into a RichText object using existing method Helper/Html::toRichTextObject. There are 2 items which need special attention.

First, for attributes like bold or italic, Excel uses the appropriate Html tag (e.g. `<B>`). However, for an attribute like color, Excel uses `<Font html:Color="#FF0000">`, with a prefix on the Color tag. PhpSpreadsheet's Html parser cannot cope with the prefix. The parser is changed to strip `html:` from attribute names for the Font tag.

The example cited by the user used a `<BR />` to indicate a line break in the data. However, it appears that, at least some of the time, Excel will instead use `&#10;` to indicate a line break. The existing parser reduces one or more whitespace characters in the text to a single space, and so `&#10;` will wind up disappearing. I am not sure why the existing code does this, but I do know that I am not willing to break it. Instead, I've added an optional boolean parameter `$preserveWhiteSpace` to `toRichTextObject`. If false (default), the existing logic will be used; but if true, substitution for whitespace characters in the text will not happen.
2024-04-30 23:51:13 -07:00
oleibman 455f1129bf RTL Text Alignment in Xlsx Comment
Fix #4004. RTL text can be included in a comment, and will display correctly, but the comment as a whole will be left-aligned. There already exists an `alignment` property for Comment, but it is unused. This PR will allow that property to be set, and to be read from and written to an Xlsx spreadsheet when possible.

The Xml tags that govern this property are found, unusually, in a drawing Vml file. The important property is `x:TextHAlign`, which can be set to Left, Right, Center, Justified, or Distributed. There are other tags which seemed like they were relevant to this problem, but I don't think they actually matter:
```xml
  <v:textbox style='mso-direction-alt:auto'>
   <div style='text-align:right;direction:rtl'></div>
  </v:textbox>
```
2024-04-30 22:22:03 -07:00
oleibman 10ec62707e Improvements to Xml Reader
Fix #3999. Fix #4000. Fix #4002. Several bug reports and feature requests for Xml Reader arrived practically simultaneously. They are all small and hit the same code modules, so I have bundled them together in one PR.
- `loadSpreadsheetFromString` might try to open a file with a falsy name (like '0'), which results in an exception with a misleading message (or a completely unexpected result if a file with that name exists). Code will still throw an exception, but the message will no longer be misleading, and no file I/O will be attempted.
- function `trySimpleXmlLoadString` is deprecated. It should never have been implemented with public visibility, and the fact that it was made the fix above a little more difficult than it would otherwise have been. It is replaced with a private equivalent.
- Style reader function `parseStyles` will now use a better namespace-aware method of reading its Xml data. Peculiarly, the Xml for the Style elements can either include or not a namespace prefix. This is probably because the global namespace and the styles namespace are the same. The existing prefix-based code does not recognize their equivalence, but the new namespace-based code does. Xml Reader continues to use prefix-based code in several other places.
- Border line styles with Weight omitted or equal to 0 have been treated as no border, but they should be treated as 'hair' thickness.
- Support for Zoom is added to Xml Reader.
- In support of the above, new properties (and getters and setters) zoomScalePageLayoutView and zoomScaleSheetLayoutView are added to Worksheet/SheetView. (As far as I can tell, Excel does not support Sheet Layout View for Xml spreadsheets).
- Support is added for those new properties in Xlsx Reader and Writer.
- Xls Reader and Writer seem to work okay without changes. There is one test where Xls shows a different value for one of the properties than Xml or Xlsx, but the spreadsheet looks okay and I don't see any practical consequences of the difference.
- PageBreak support is added to Xml Reader.
- Code for writing out Column Page Breaks in Xlsx Writer was wrong (and, unsurprisingly, untested). A one-line change fixes it, and tests are added.
2024-04-27 16:42:42 -07:00
oleibman 34272571f5 Merge pull request #3992 from oleibman/issue3988
Table Filter Buttons
2024-04-20 14:32:03 +00:00
oleibman 98ab11cf5f Table Filter Buttons
Fix #3988. Excel allows a table to have some colums with filter buttons exposed and some with filter buttons hidden. However you cannot do this in "native" Excel - VBA is required for this feature. PhpSpreadsheet is supposed to be able to handle this, but Xlsx/Writer/Table had a bug. The `filterColumn` tags in the xml should be children of the `autoFilter` tag, but were generated as siblings. Moving one statement fixes that problem. Fixing that exposed another problem - autoFilter `showHideRows` was not properly recognizing that a filter could exist without any rules, which is what happens when a table filter button is hidden. Another simple change fixes that problem.

The parent issue correctly points out the problem for Column D in samples/Table/01_Table. However, that sample also has a problem with Column A - unlike columns B and C, there is a filter appled to column A, so its dropdown button should appear different than those in B and C. That problem is also corrected with the fixes above. I also added some formal tests based on that sample.
2024-04-17 10:45:58 -07:00
oleibman e9f03dfe36 Merge pull request #3946 from Phenix789/master
Fix default value for Conditional::$text
2024-04-17 02:27:33 +00:00
oleibman c84bdbf015 Add Test Case 2024-04-16 19:18:40 -07:00
oleibman f7cf378fae Merge pull request #3957 from oleibman/htmlcomments
Html Writer Comments - Breaking Change
2024-04-14 23:24:47 +00:00
oleibman f20688c179 Typo In Previous PR 2024-03-27 14:06:34 -07:00
oleibman c695d5ca8b Minor Correction
Sanitize font name.
2024-03-27 14:01:13 -07:00
oleibman f64e0ecd79 Merge branch 'master' into issue3951 2024-03-24 17:40:54 -07:00
oleibman 989a4cec54 Html Writer Comments - Breaking Change
Fix #3954. In response to a Security Incident, a package was added to the project to sanitize the Html for comments attached to a cell. We have tried at least 2 different packages for this purpose, and users have raised legitimate concerns about both.

I believe that adding a sanitizer package, although it addresses the problem, was overkill. Cell comments are a RichText object, and Html Writer already handled RichText cell *values*. Values did not figure in the Incident, and they surely would have done so if they were a problem because it is a lot easier to set up test cases for values than for comments. RichText values were not a problem because they were sanitized with `htmlspecialchars`; if comments were to use the same code that RichText was already using, it would likewise be safely sanitized. As an added bonus, the existing code for comments only uses the plaintext value, but the values code would allow the comments to be styled, just as they are for Xlsx.

This is a breaking change - I don't think it will affect a lot of users, but there may be some. It is worth noting that the comment block before function `writeComment` has a link explaining what is being done. That link mentions only styling elements, not other possibilities like hyperlinks. At any rate, if people are putting styling tags (e.g. `<b>`) in their comments for this purpose, those will no longer work; the styling needs to be applied to the RichText elements. That will keep the user code the same regardless of the format of the intended output, which is certainly a good thing, but it is a break. If people are trying to insert non-styling tage (e.g. `<a>`), those will no longer work, just as there is no way to do it for Xlsx (although Excel itself may convert the raw text to a hyperlink, but that's out of scope, at least for now). I also note that, even with the current code, I haven't yet found a way to keep the Html comment in place long enough to actually click on any hyperlinks.

The main package being dropped brings several other packages along with it, so the project as a whole will have a slightly lighter footprint than before.

The existing `XssVulnerability` test cases are all preserved. Although the final result of the sanitizing changes, it can easily be seen that the results are all harmless.
2024-03-20 10:57:16 -07:00