Skip to content

Commit e37e01c

Browse files
authored
fix #596: prevent events search category from over-extracting fields (#606)
- Fix splitLines logic to split by newlines before normalizing whitespace in linkedinSearch.ts and linkedinEvents.ts - Add e2e assertions to ensure title and date_time fields are reasonably sized
1 parent 863ab63 commit e37e01c

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

packages/core/src/__tests__/e2e/events.e2e.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ describe("Events E2E", () => {
2929
const first = result.results[0]!;
3030
expect(first.event_id.length).toBeGreaterThan(0);
3131
expect(first.title.length).toBeGreaterThan(0);
32+
expect(first.title.length).toBeLessThan(200);
3233
expect(typeof first.date_time).toBe("string");
34+
expect(first.date_time.length).toBeLessThan(100);
3335
expect(typeof first.location).toBe("string");
3436
expect(typeof first.organizer).toBe("string");
3537
expect(typeof first.attendee_count).toBe("string");

packages/core/src/__tests__/e2e/search.e2e.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ describe("Search E2E", () => {
129129
expect(first).toBeDefined();
130130
if (first) {
131131
expect(first.title.length).toBeGreaterThan(0);
132+
expect(first.title.length).toBeLessThan(200);
133+
expect(first.date.length).toBeLessThan(100);
132134
}
133135
});
134136

packages/core/src/linkedinEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ async function extractEventSearchResults(
344344
return uniqueLinks.slice(0, maxEvents).map((link) => {
345345
const card = link.closest("li") ?? link.closest("div[data-view-tracking-scope]") ?? link.closest("div.search-result__wrapper") ?? link.parentElement;
346346

347-
const rawText = normalize((card as HTMLElement)?.innerText ?? link.innerText ?? "");
347+
const rawText = (card as HTMLElement)?.innerText ?? link.innerText ?? "";
348348
const lines = rawText
349349
.split("\n")
350350
.map((line) => normalize(line))

packages/core/src/linkedinSearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,7 @@ export class LinkedInSearchService {
22952295

22962296
return Array.from(globalThis.document.querySelectorAll("main li, div.search-results-container ul > li, ul.reusable-search__entity-result-list > li"))
22972297
.map((card) => {
2298-
const lines = normalize((card as HTMLElement).innerText)
2298+
const lines = ((card as HTMLElement).innerText || "")
22992299
.split("\n")
23002300
.map((line) => normalize(line))
23012301
.filter(Boolean);

0 commit comments

Comments
 (0)