Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser (streamed): fix default value for cell type #154

Merged
merged 5 commits into from
May 13, 2022

Conversation

NikitaRazmakhnin
Copy link
Contributor

@NikitaRazmakhnin NikitaRazmakhnin commented May 12, 2022

According to [ECMA-376] specification of XML schema of Excel default type for cell is n - number.
This is how it is implemented in regular parser, but streamed option was a bit incorrect here.

Spec declares such schema:
<xsd:attribute name="t" type="ST_CellType" use="optional" default="n"/>

According to specification if cell has no t attribute, it has a default value as n - number.
But Untyped caused wrapping of numeric values into text instead.
As far as I understand it should be CellDouble in all cases where t is omitted.

@qrilka
Copy link
Owner

qrilka commented May 12, 2022

Thanks @NikitaRazmakhnin
Would you mind adding a test covering this case?

@NikitaRazmakhnin
Copy link
Contributor Author

Thanks @NikitaRazmakhnin
Would you mind adding a test covering this case?

Sure, will do! :)

According to specification if cell has no `t` attribute,
it has a default value as `n` - number.
@NikitaRazmakhnin
Copy link
Contributor Author

@qrilka tests are done. I verified they fail with wrong value-type before fix and are green after the fix.

, IM.fromList [ (1, def & cellValue ?~ CellDouble 14.0 & cellStyle ?~ 1 ) ]
, IM.fromList [ (1, def & cellValue ?~ CellDouble 15.0) ]
]
expected @==? (_ri_cell_row . _si_row <$> items)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about checking the same for the non-streamed parser? It makes sense to ensure that they do the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote integration test around of that since I do not see an opportunity how
to test parseCell in more isolated manner, because parseCell are defined
deeply in functions of whole archive parsing.

I hope its fine for now to use it that way? I wrote same test for both parsers (Xeno and Cursored).

@@ -688,7 +688,7 @@ parseStyle list =
parseType :: SheetValues -> Either TypeError ExcelValueType
parseType list =
case findName "t" list of
Nothing -> pure Untyped
Nothing -> Right TN -- according to spec by default if `t` is missing then default value is `n` - number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could find a specific place in the spec talking about this? If no I could take a look a bit later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I get you correctly that you propose to throw a reference to the spec here?
If so, I can do that no problems. Should I highlight it as well in comment for non-streamed parser?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, section of the spec (or maybe reference to the schema?) would be great to prove the logic here or actually both places (or you could reference one from another)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I placed wrong schema reference in the PR description (was reading specs in the first time
and was a bit confused by naming conventions). Now its clear to me what exactly to read :)

But I threw a correct ECMA references with paragraph numbers and quotes from xsd, because
could not find online format of that. Hope its fine!

@qrilka
Copy link
Owner

qrilka commented May 13, 2022

@NikitaRazmakhnin please take a look into the failure with microlens

@qrilka qrilka merged commit 11df85f into qrilka:master May 13, 2022
@qrilka
Copy link
Owner

qrilka commented May 13, 2022

Thanks @NikitaRazmakhnin for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants