Skip to content

Commit c3dcfc8

Browse files
committed
Fix numeric hash type handling
1 parent 764f583 commit c3dcfc8

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/__tests__/parsers/interlinearXmlParser.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ describe('InterlinearXmlParser', () => {
7676
expect(result.Verses['RUT 3:1'].Hash).toBe('ABC123');
7777
});
7878

79+
it('parses purely numeric verse Hash', () => {
80+
const xml = `
81+
<InterlinearData ScrTextName="MyProject" GlossLanguage="en" BookId="RUT">
82+
<Verses>
83+
<item>
84+
<string>RUT 3:1</string>
85+
<VerseData Hash="123456">
86+
<Cluster>
87+
<Range Index="1" Length="2" />
88+
<Lexeme Id="x" />
89+
</Cluster>
90+
</VerseData>
91+
</item>
92+
</Verses>
93+
</InterlinearData>
94+
`;
95+
const result = parser.parse(xml);
96+
97+
expect(result.ScrTextName).toBe('MyProject');
98+
expect(result.Verses['RUT 3:1'].Hash).toBe('123456');
99+
});
100+
79101
it('parses cluster with multiple lexemes and builds LexemesId and Id correctly', () => {
80102
const xml = `
81103
<InterlinearData GlossLanguage="en" BookId="MAT">

src/parsers/interlinearXmlParser.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ import type {
88
VerseData,
99
} from 'interlinearizer';
1010

11-
/**
12-
* Range: Index and Length attributes from fast-xml-parser. We set parseAttributeValue: true so
13-
* numeric attributes (Index, Length) are parsed as numbers; no manual Number() at use sites.
14-
*/
11+
/** Range: Index and Length attributes. */
1512
interface ParsedRange {
1613
/** Start index in source text (FXP attribute Index). */
17-
['@_Index']: number;
14+
['@_Index']: string;
1815
/** Length of range (FXP attribute Length). */
19-
['@_Length']: number;
16+
['@_Length']: string;
2017
}
2118

2219
/** Lexeme: Id (required), optional GlossId. */
@@ -186,8 +183,8 @@ export class InterlinearXmlParser {
186183
private readonly parser: XMLParser;
187184

188185
/**
189-
* Creates a parser configured for interlinear XML: attribute prefix `@_`, numeric attributes
190-
* parsed as numbers, and array paths for Verses items, Cluster, Punctuation, and Lexeme.
186+
* Creates a parser configured for interlinear XML: attribute prefix `@_`, and array paths for
187+
* Verses items, Cluster, Punctuation, and Lexeme.
191188
*/
192189
constructor() {
193190
const options: Partial<X2jOptions> = {
@@ -197,7 +194,7 @@ export class InterlinearXmlParser {
197194
ignorePiTags: true,
198195
trimValues: true,
199196
parseTagValue: false,
200-
parseAttributeValue: true,
197+
parseAttributeValue: false,
201198
isArray: (_tagName, jPath) => {
202199
return [
203200
'InterlinearData.Verses.item',

0 commit comments

Comments
 (0)