Skip to content

Commit

Permalink
Strip leading slash from logical names
Browse files Browse the repository at this point in the history
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.

<http://www.ecma-international.org/publications/standards/Ecma-376.htm>
  • Loading branch information
luke-clifton committed Jan 14, 2024
1 parent 426eb0a commit d0c2864
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 d0c2864

Please sign in to comment.