Skip to content

Commit

Permalink
fix: invalid compressing flag implementation (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: sungho <[email protected]>
  • Loading branch information
snibug authored Apr 9, 2024
1 parent 56db0d3 commit b631063
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/parser/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,30 @@ function parseDocInfo(container: CFB$Container, header: HWPHeader): DocInfo {
}

const content: Uint8Array = docInfoEntry.content as Uint8Array
const decodedContent: Uint8Array = inflate(content, { windowBits: -15 })

return new DocInfoParser(header, decodedContent, container).parse()
if (header.properties.compressed) {
const decodedContent: Uint8Array = inflate(content, { windowBits: -15 })
return new DocInfoParser(header, decodedContent, container).parse()
} else {
return new DocInfoParser(header, Uint8Array.from(content), container).parse()
}
}

function parseSection(container: CFB$Container, sectionNumber: number): Section {
function parseSection(container: CFB$Container, header: HWPHeader, sectionNumber: number): Section {
const section = find(container, `Root Entry/BodyText/Section${sectionNumber}`)

if (!section) {
throw new Error('Section not exist')
}

const content: Uint8Array = section.content as Uint8Array
const decodedContent: Uint8Array = inflate(content, { windowBits: -15 })

return new SectionParser(decodedContent).parse()
if (header.properties.compressed) {
const decodedContent: Uint8Array = inflate(content, { windowBits: -15 })
return new SectionParser(decodedContent).parse()
} else {
return new SectionParser(Uint8Array.from(content)).parse()
}
}

function parse(input: CFB$Blob, options?: CFB$ParsingOptions): HWPDocument {
Expand All @@ -128,7 +136,7 @@ function parse(input: CFB$Blob, options?: CFB$ParsingOptions): HWPDocument {
const sections: Section[] = []

for (let i = 0; i < docInfo.sectionSize; i += 1) {
sections.push(parseSection(container, i))
sections.push(parseSection(container, header, i))
}

return new HWPDocument(header, docInfo, sections)
Expand Down

0 comments on commit b631063

Please sign in to comment.