Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class DataExtractor {
}
let labelElement: Element | null;
try {
labelElement = parent.querySelector(':scope>span,h1,h2,h3,h4,h5,h6');
labelElement = parent.querySelector(':scope>span,:scope>h1,:scope>h2,:scope>h3,:scope>h4,:scope>h5,:scope>h6');
} catch {
/* istanbul ignore next */
labelElement = null;
Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-autocapture-browser/test/data-extractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,20 @@ describe('data extractor', () => {
expect(result).toEqual('nearest label');
});

test('should not return a deeply nested label of the element (regression test)', () => {
const container = document.createElement('div');
const heading = document.createElement('h1');
heading.innerText = 'My App';
const form = document.createElement('form');
const input = document.createElement('input');
container.appendChild(heading);
form.appendChild(input);
container.appendChild(form);

const result = dataExtractor.getNearestLabel(input);
expect(result).toEqual('');
});
Comment thread
daniel-graham-amplitude marked this conversation as resolved.

test('should return masked nearest label when content is sensitive', () => {
const div = document.createElement('div');
const span = document.createElement('span');
Expand Down
Loading