Skip to content

Commit

Permalink
fix: remove BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
mdvorak committed Apr 15, 2023
1 parent 7d39025 commit 23fd4a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/properties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ describe('parse', () => {
'extra'
])
})

it('should remove BOM', () => {
const sample = '\ufefffoo=bar\n#test'

// Test
const result = properties.parse(sample)
expect(result.lines).toEqual(['foo=bar', '#test'])
})
})

describe('stringify', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const parse = (contents: string): Properties => {
lines.pop()
}

// Remove BOM from the first line
if (lines.length > 0 && lines[0].codePointAt(0) === 0xfeff) {
lines[0] = lines[0].slice(1)
}

return {lines}
}

Expand Down Expand Up @@ -473,7 +478,7 @@ const parseUnicode = (sequence: string, line: number): string => {
if (!sequence.match(/^0x[\da-fA-F]{4}$/)) {
throw new Error(`Invalid unicode sequence at line ${line}`)
}
return String.fromCharCode(parseInt(sequence, 16))
return String.fromCodePoint(parseInt(sequence, 16))
}

/**
Expand Down

0 comments on commit 23fd4a1

Please sign in to comment.