Skip to content

Commit

Permalink
[REPLAY] Fix serialization for checkbox & radio
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibautGeriz committed Feb 17, 2023
1 parent a483e80 commit 157f74f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
60 changes: 60 additions & 0 deletions packages/rum/src/domain/record/serialize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,66 @@ describe('serializeNodeWithId', () => {
)
})

it('serializes <input type="radio"> elements checked state', () => {
const radio = document.createElement('input')
radio.type = 'radio'
expect(serializeNodeWithId(radio, DEFAULT_OPTIONS)! as ElementNode).toEqual(
jasmine.objectContaining({
attributes: {
type: 'radio',
value: 'on',
checked: false,
},
})
)

radio.checked = true

expect(serializeNodeWithId(radio, DEFAULT_OPTIONS)! as ElementNode).toEqual(
jasmine.objectContaining({
attributes: {
type: 'radio',
value: 'on',
checked: true,
},
})
)
})

it('serializes <input type="radio"> elements checked state with mask serialization', () => {
const radio = document.createElement('input')
radio.type = 'radio'
expect(
serializeNodeWithId(radio, {
...DEFAULT_OPTIONS,
parentNodePrivacyLevel: NodePrivacyLevel.MASK_USER_INPUT,
})! as ElementNode
).toEqual(
jasmine.objectContaining({
attributes: {
type: 'radio',
value: '***',
},
})
)

radio.checked = true

expect(
serializeNodeWithId(radio, {
...DEFAULT_OPTIONS,
parentNodePrivacyLevel: NodePrivacyLevel.MASK_USER_INPUT,
})! as ElementNode
).toEqual(
jasmine.objectContaining({
attributes: {
type: 'radio',
value: '***',
},
})
)
})

it('serializes <audio> elements paused state', () => {
const audio = document.createElement('audio')

Expand Down
2 changes: 1 addition & 1 deletion packages/rum/src/domain/record/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function getAttributesForPrivacyLevel(
if (nodePrivacyLevel === NodePrivacyLevel.ALLOW) {
safeAttrs.checked = !!inputElement.checked
} else if (shouldMaskNode(inputElement, nodePrivacyLevel)) {
safeAttrs.checked = CENSORED_STRING_MARK
delete safeAttrs.checked
}
}

Expand Down
4 changes: 0 additions & 4 deletions packages/rum/test/htmlAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ export const AST_MASK = {
type: 'checkbox',
name: 'inputFoo',
value: '***',
checked: '***',
},
childNodes: [],
},
Expand Down Expand Up @@ -372,7 +371,6 @@ export const AST_MASK = {
type: 'radio',
name: 'radioGroup',
value: '***',
checked: '***',
},
childNodes: [],
},
Expand Down Expand Up @@ -655,7 +653,6 @@ export const AST_MASK_USER_INPUT = {
type: 'checkbox',
name: 'inputFoo',
value: '***',
checked: '***',
},
childNodes: [],
},
Expand Down Expand Up @@ -687,7 +684,6 @@ export const AST_MASK_USER_INPUT = {
type: 'radio',
name: 'radioGroup',
value: '***',
checked: '***',
},
childNodes: [],
},
Expand Down

0 comments on commit 157f74f

Please sign in to comment.