diff --git a/parsers.js b/parsers.js index 4f34ac9..00bc265 100644 --- a/parsers.js +++ b/parsers.js @@ -48,7 +48,9 @@ function parseProfilePage(html) { const result = {}; - const bMatch = /([\s\S]*?)<\/b>/i.exec(html); + const h3Match = /]*>([\s\S]*?)<\/h3>/i.exec(html); + const bMatch = (h3Match && /([\s\S]*?)<\/b>/i.exec(h3Match[1])) || + /([\s\S]*?)<\/b>/i.exec(html); if (bMatch) result.program = cleanText(bMatch[1]); const smallMatch = /([\s\S]*?)<\/small>/i.exec(html); @@ -57,7 +59,7 @@ result.semester = lines[lines.length - 1] || ''; } - const kvRe = /]*>([\s\S]*?)<\/td>\s*]*class="bold"[^>]*>([\s\S]*?)<\/td>/gi; + const kvRe = /]*>([\s\S]*?)<\/td>\s*]*class=["'][^"']*\bbold\b[^"']*["'][^>]*>([\s\S]*?)<\/td>/gi; let m; while ((m = kvRe.exec(html)) !== null) { const key = cleanText(m[1]); diff --git a/test/parsers.test.js b/test/parsers.test.js index 7573bc2..48536d6 100644 --- a/test/parsers.test.js +++ b/test/parsers.test.js @@ -34,6 +34,26 @@ test('parseProfilePage extracts header fields', () => { assert.strictEqual(p.fullName, 'ADRIAN ALFRED CHIONG BONPIN'); assert.strictEqual(p.studentId, '22103625'); assert.strictEqual(p.yearLevel, '4'); + assert.strictEqual(p.studentType, 'CONTINUING'); assert.strictEqual(p.program, 'BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY'); assert.strictEqual(p.semester, '1ST Semester 2026'); }); + +test('parseProfilePage matches bold class token with single quotes and extra classes', () => { + const html = ` +

BACHELOR OF SCIENCE

+ + + +
Full NameJOHN DOE
Student TypeCONTINUING
+ `; + const p = parseProfilePage(html); + assert.strictEqual(p.fullName, 'JOHN DOE'); + assert.strictEqual(p.studentType, 'CONTINUING'); + assert.strictEqual(p.program, 'BACHELOR OF SCIENCE'); +}); + +test('parseProfilePage degrades gracefully on empty input', () => { + const p = parseProfilePage(''); + assert.deepStrictEqual(p, {}); +});