Skip to content

Commit

Permalink
Merge pull request #172 from luke-clifton/logicaltozipname
Browse files Browse the repository at this point in the history
Strip leading slash from logical names
  • Loading branch information
qrilka authored Jan 14, 2024
2 parents 426eb0a + d0c2864 commit d9ea2d5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Codec/Xlsx/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,20 @@ getRels ar fp = do
c <- xmlCursorOptional ar relsPath
return $ maybe Relationships.empty (setTargetsFrom fp . headNote "Missing rels" . fromCursor) c

-- According to part 2, section 7.3.4 of ECMA-376, when mapping logical item
-- names to ZIP item names we need to remove the leading slash.
--
-- Non-ASCII characters should be percent-encoded as well, but this is not
-- currently implemented.
--
-- https://ecma-international.org/publications-and-standards/standards/ecma-376/
logicalNameToZipItemName :: FilePath -> FilePath
logicalNameToZipItemName ('/' : name) = name
logicalNameToZipItemName name = name

lookupRelPath :: FilePath
-> Relationships
-> RefId
-> Either ParseError FilePath
lookupRelPath fp rels rId =
relTarget <$> note (InvalidRef fp rId) (Relationships.lookup rId rels)
logicalNameToZipItemName . relTarget <$> note (InvalidRef fp rId) (Relationships.lookup rId rels)

0 comments on commit d9ea2d5

Please sign in to comment.