Commit Graph

241 Commits

Author SHA1 Message Date
oleibman 5c94de34a9 More Phpstan Level 10 Prep - Readers
Also upgrade Phpstan.
2025-05-03 21:18:55 -07:00
oleibman de9fdc3855 XML Reader Recognize Indents
Fix #4448
2025-04-20 16:10:50 -07:00
oleibman 5ce46da559 Merge branch 'master' into issue4435 2025-04-05 17:29:22 -07:00
oleibman 5b799dbbed Ods Reader No Datatype for Null Value
Issue #4435 was initially described incorrectly. While investigating the original description, I came upon this problem. Ods Reader is trying to set some cells to null without supplying a valid DataType to setValueExplicit, causing that method to throw an exception. Reader is changed to no longer call that method when value is null and DataType is null-string.
2025-04-03 19:55:33 -07:00
oleibman 2213139d96 Merge branch 'master' into issue4416 2025-03-27 00:01:29 -07:00
oleibman 6b61da0017 Column Widths Not Preserved When Using Read Filter
Fix #4416. A peculiar problem indeed. PhpSpreadsheet has been considering a column to be filtered if any cell in the column is filtered and does not preserve the column width if that is the case. It should consider the column not filtered if any cell in the column is not filtered, and consider it filtered only if there are no cells to which that applies. At least, that's how I think it should work, and this change doesn't break any existing tests, and solves this issue.
2025-03-24 20:18:51 -07:00
oleibman 71b243539a Ignore Fractional Part of Drawing Shadow Alpha
Fix #4415. We store the rarely-used property Drawing/Shadow/Alpha as an integer representing the percentage. Excel also stores it as an integer, but multiplies it by 1,000, so we divide by 1,000 when we read this value. This can, and in the case of the issue at hand does, leave a fractional portion. Php has deprecated passing a float with a fractional portion to an int argument, so the reporter saw a deprecation message. This is easily fixed.
2025-03-20 20:11:11 -07:00
oleibman 190af743f8 Add FormulaRange to IgnoredErrors Possibilities
When I implemented IgnoredErrors (PR #3508), I dealt only with those that I understood well enough to come up with an example. I finally found an example for FormulaRange in the wild, so this PR adds it. Still unsupported are `calculatedColumn`, `emptyCellReferece`, `listDataValidation`, and `unlockedFormula`.
2025-03-03 20:16:12 -08:00
oleibman 01539876b1 Merge branch 'master' into issue4375 2025-02-23 12:28:17 -08:00
oleibman d813d7efcb Merge pull request #4360 from oleibman/issue4536
Xlsx Reader Defined Name on Sheet with Apostrophe in Title
2025-02-21 01:32:02 +00:00
oleibman 2b7e6f50a2 Ignore ignoredErrors when Not Applicable
Fix #4375. Do not set ignoredErrors when using readDataOnly, not when the cell to which it applies doesn't exist.
2025-02-19 19:15:01 -08:00
oleibman ae6c92b006 More Tests 2025-02-17 22:45:05 -08:00
oleibman 8930e634a1 Add Some Tests 2025-02-17 17:58:17 -08:00
oleibman 9b07be9a0f Add sheetState to ListWorksheetInfo Data
Fix #4345. Add a new item to the output array. Although the output is changed, this does not seem like a breaking change to me.
2025-02-14 23:40:50 -08:00
oleibman eafbed6ca8 Merge pull request #4314 from oleibman/issue4312
CF Priority Property and Overlapping Ranges
2025-02-04 04:35:13 +00:00
oleibman cfc8b8c26f Merge branch 'master' into issue797 2025-02-03 17:50:15 -08:00
oleibman cde2926a9e Merge commit from fork
* Security Patch

Control characters should not be allowed in protocol.

* Tighten Up Drawing

* Fix Test
2025-01-23 21:25:36 -08:00
oleibman 8d7500b1e2 Merge branch 'master' into issue4312 2025-01-21 19:58:05 -08:00
oleibman 41ca105c88 Handle Overlapping Ranges
Fix #4318. Also make getConditionalStyles more useful, by adding a non-default parameter so that all rules pertaining to a single-cell coordinate can be returned, and in priority order. By default, just the first matching rule will be returned.
2025-01-14 20:57:55 -08:00
oleibman 07fbe9a1fc Merge branch 'master' into issue797 2025-01-11 22:51:54 -08:00
oleibman 56e7422bba Add "Priority" Property for Conditional Formatting
Fix #4311. Excel applies Conditional Formatting rules according to a priority specified in the xml. The priority must be a natural number; the rules are applied in order from lowest priority number to highest. When reading an Xlsx spreadsheet, PhpSpreadsheet has been ignoring the priority, which can result in differences from Excel's behavior, especially when CF cell ranges overlap (note that overlapping ranges are not supported in Xls format).

If an application uses PhpSpreadsheet to add new Conditional Formatting to a worksheet and does not change its priority from the default (0), the Xlsx Writer will assign a priority with a higher value than any of the CF objects which have been assigned a priority (either from reading it or explicitly assigning it).
2025-01-11 17:31:52 -08:00
oleibman f25502d704 Merge branch 'master' into groupby 2025-01-08 14:53:51 -08:00
oleibman 270695ae06 Merge branch 'PHPOffice:master' into issue4280 2024-12-30 16:31:46 -08:00
oleibman 38c4ce4836 Additional Coverage For Xml Reader
No source code changes.
2024-12-30 10:40:01 -08:00
oleibman 45052f88e0 Merge commit from fork 2024-12-26 16:34:48 -08:00
oleibman 9fc8e501b8 Extremely Limited Support for GROUPBY Function
This is a partial response to issue #4282. The actual logic to implement GROUPBY is probably very complicated. And, even worse, Excel has thrown a whole new way of (internally) specifying one of the arguments into the mix. That argument is a function name, expressed not as a mapped integer (as SUBTOTAL does), nor even as a string, but as the unquoted function name prefixed by `_xleta.`. And, unlike its `_xlfn.` and `_xlws.` predecessors, it is difficult to figure out when the new prefix needs to be added, and when it needs to be ignored. I am not even going to attempt that task with this ticket.

So, what does this change do? Like earlier attempts to introduce limited functionality (such as with form controls), it is there so that using GROUPBY can be passed through - you can load a spreadsheet that contains it, and save it to a new spreadsheet, and the function and its results are preserved. Some cautionary notes. Dynamic arrays must be enabled (the function makes no sense without doing that). Changing any of the inputs used in the function may result in internal inconsistencies between PhpSpreadsheet and Excel; this is especially so if the dimensions of the returned array change as a result of changes to the input data. The programmer can avoid some of these problems by changing the formulatAttributes of the cell where the function is used; this may be difficult to do in practice. Oh, yes, using the GROUPBY cell as an argument in another formula will probably lead to problems. Finally, I confess that part of this solution looks awfully kludgey to me.

With its limitations and those cautions, is it worth proceeding with this change? My gut feel is that it is more useful to proceed than not. However, I will give others the opportunity to weigh in. I will wait at least a couple of weeks into the new year before proceeding with this.
2024-12-18 17:28:36 -08:00
oleibman cf5bf08904 Xlsx Reader Shared Formula with Boolean Results
A solution, at least in part, for issue #4280. Xlsx Reader is not handling shared formulae correctly. As a result, some cells are treated as if they contain boolean values rather than formulae.
2024-12-16 23:57:51 -08:00
oleibman e6d92201fe Slight Increase in Coverage Reading BIFF8
After breaking up Xls Reader (PR #4118), it is a little easier to identify uncovered code. BIFF8 had no tests involving constant arrays. This PR adds some. Most of the work is in the tests, but some source code is modernized to use things like null coercion.
2024-12-14 09:13:26 -08:00
oleibman dd69858111 Fill Patterns/Colors When Xml Attributes are Missing
Fix #4248. PhpSpreadsheet has used what appear to be default attributes and tags when they are missing from Fill patterns and colors. However, Excel handles their absence a little differently from what the "default" would require. PhpSpreadsheet is changed to omit the attributes and tags in question when missing. This change is mostly targeted towards Xlsx read and write, but minor changes for Xls and Html write are also included.

This seems like it could be a breaking change, but I don't think it is. One test (DefaultFillTest introduced by PR #2050) must change, but the change is internal - loading and then saving the spreadsheet used in that change will appear the same after this change as it did before. Other differences are very likely to be bug fixes rather than breaks.
2024-11-29 20:08:11 -08:00
oleibman 9ab866f409 Ignore Settings::libXmlLoaderOptions
Having addressed several security advisories, one evident *theoretical* problem remains. This is an attempt to future-proof our code against similar vulnerabilities. It all begins with our implementation of libXmlLoaderOptions, which uses as a default LIBXML_DTDLOAD. This unfortunate choice opens us to XXE problems, many recently solved. I do not believe that there is a legitimate use case for allowing this, and will therefore ignore and deprecate that option.

Although this might seem to be a breaking change, it is not. The setting is used only after the Xml has been subject to a security scan, and the security scan throws an exception if it detects the use of `<!DOCTYPE` within the Xml. Therefore, the setting will be effective only on Xml which does not contain that tag, and will consequently have no effect on most Xml. The only exception would be Xml which has been crafted to avoid detection by the security scanner in a manner which has not been disclosed to us. Although we hope that we've now blocked all such avenues, this provides additional protection just in case.

With this change in place, we could relax certain restrictions, e.g. the use of EBCDIC or even UTF-7. For now, these will remain in place. I will need to be convinced that there is a legitimate use case for easing the restrictions before doing so. We might even consider the elimination of the Security Scanner altogether. However, it does allow for early detection, and, in any case, provides a method to correct Xml which most Xml readers would fail but which Excel accepts.

My plan is to merge this within the next few days, and tag a new release immediately after. It will also be backported to all active branches.
2024-11-18 22:28:35 -08:00
oleibman c04a9389d3 Merge commit from fork
* Security Patch

* Throw Exception for EBCDIC Encoding

* Mixed UTF-8 and UTF-16

Further mischief. I don't know if the examples truly are valid Xml, but PhpSpreadsheet is letting them sneak through.
2024-11-10 01:07:59 -08:00
oleibman 753732b5c3 Merge branch 'master' into csvphp9 2024-10-14 21:12:16 -07:00
oleibman 545b098acd Method to Test Whether Csv Will Be Affected by Php9
See #4161. The best way to future-proof is to set the escape character to null string, and set testAutoDetect to false before reading. However, depending on the file being read, this may lead to different results than expected. This will be unavoidable because Php itself will change. This PR adds a new static method `affectedByPhp9` to Csv Reader. This can be used to identify in advance whether an input file will be affected by the changes. This will allow users to identify problems in advance, and prepare for how they might be handled.
2024-10-09 07:07:16 -07:00
oleibman 32cb9f488f Excel 2003 Allows Html Entities
Fix #2157. Excel 2003 format allows some things which a real Xml parser would reject. In particular, it permits Html entities, and leading whitespace. Change Xml Reader to do likewise.
2024-10-06 09:32:11 -07:00
oleibman 4b8a929fc1 Merge commit from fork
* Validate Mime Type for Images

* Extend Change to Xlsx Reader

* Attach Drawing to Sheet Only If Valid

* Suppress Some Theoretical Warning Messages

* Minor Tweak
2024-09-23 13:28:31 -07:00
oleibman 63ccb02ab9 Merge commit from fork
* Check for Whitespace Around Xml Encoding

* More Tests
2024-09-13 18:17:30 -07:00
oleibman 30384ac043 Xls Reader Some Ranges Not Handled Properly
This supersedes PR #607 by @christian-forgacs, who deserves all the credit for reporting the problem and devising the solution. The PR went stale in 2018, and it is just easier to resubmit a clean version rather than clean up the old one. Among the suggestions in the PR was that you should try to create a spreadsheet from scratch to demonstrate the problem rather than supply one. However, my attempts to match the failing spreadsheet do not have a problem when they are read. So, a supplied spreadsheet it is.

Fix #1570. No sample spreadsheet was supplied with that issue, but I am almost certain that this is another example of the same problem. I am removing the stale label from that issue; it will be closed properly when this PR is merged.
2024-08-13 14:27:42 -07:00
oleibman 768dd75ba1 Merge branch 'master' into atsign 2024-07-30 22:51:13 -07:00
Adrien Crivelli bea2d4b30f Security: prevent XXE (XML External Entity) when loading files
Prevent XEE by hiding custom entities by using single quote to
declare a non-UTF-8 encoding.

XML standard, https://www.w3.org/TR/xml/#NT-EncodingDecl, allows single
quote to declare encoding, but we did not support it. Instead, we
incorrectly fell back on the default of UTF-8. That incorrectly kept the
XML as non-UTF-8, and thus prevented our regexp-based custom entity
detection mechanism to work.
2024-07-29 16:22:43 +09:00
oleibman ab5965affb Merge branch 'master' into issue4099 2024-07-27 07:36:13 -07:00
oleibman 312cd5a6a0 Merge branch 'master' into atsign 2024-07-23 06:25:08 -07:00
oleibman 2952cf5526 Ods Reader Allow Omission of Some Page Settings Tags
Fix #4099. Ods Reader was expecting there to always be `header-style` and `footer-style` tags when `page-layout` tag is present, but these need not exist. It seemed like there might be other exposures along this line in `readPageSettingStyles`; rather than waiting for a problem report to show up for each, the code is updated to use `->item(0)` in place of `[0]` when appropriate, and make use of the nullsafe `?->` operator introduced with Php8.
2024-07-18 13:30:58 -07:00
oleibman 2c150d5381 Merge branch 'master' into issue804 2024-07-10 20:14:46 -07:00
oleibman b22d1f52e7 Merge branch 'master' into atsign 2024-07-07 16:46:50 -07:00
oleibman 96f09441ca Merge branch 'master' into issue4081 2024-07-07 07:27:49 -07:00
oleibman 22bac3eb49 Merge branch 'master' into issue2581 2024-07-05 22:48:45 -07:00
oleibman 1d86675e04 Ods Xml Reader and Whitespace Text Nodes
Fix #804, opened in Dec. 2018, and closed as stale in Feb. 2019, and which I have re-opened to be closed properly by this PR. Better late than never, I suppose. A third party generated an ODS spreadsheet which PhpSpreadsheet could not read. By way of explanation, the xml in the file contained lots of whitespace between tags, which is wonderful for those humans among us who have to analyze it; but PhpSpreadsheet was not prepared for it. It is now.
2024-07-03 19:56:38 -07:00
oleibman 8557ccb72a Ods Comments With Newlines
Fix #4081. Ods Reader was not reading entire contents of comment. On further inspection, Ods Writer also was not handling comments completely correctly. Ods comments are recorded as `text:p` children of `office:annotation` elements. A newline is inserted between successive `text:p` elements. The `text:p` element itself can have as descendants (at least):
- raw text
- `text:span` elements
- `text:line-break` elements, which also causes the insertion of a newline

Ods Writer is changed to use a single `text:p` with multiple span/linebreak elements. Ods Reader is changed to process in their entirety either that form, or multiple `text:p` elements. Styling of the individual elements of the comment is permitted in Ods. That has not been supported till now by PhpSpreadsheet, and this PR will not address that situation - Ods Reader hast little style support, and this would hardly be the most urgent case where it is missing.
2024-07-01 14:52:23 -07:00
oleibman edf7f71e2a Merge branch 'master' into atsign 2024-06-30 00:28:18 -07:00
oleibman b051d4946c Use CELL("width") As Another Unimplemented Array Function
I might want to implement CHOOSECOLS after this PR is merged.
2024-06-29 23:28:21 -07:00