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 @@ -112,7 +112,7 @@ class StateValue {
input: any,
public namespaceId: string = '',
) {
const isObj = input && input.hasOwnProperty('value');
const isObj = input && Object.hasOwn(input, 'value');
const value = isObj ? input['value'] : input;
this.value = normalizeTriggerValue(value);
if (isObj) {
Expand Down Expand Up @@ -246,7 +246,7 @@ class AnimationTransitionNamespace {

let fromState = triggersWithStates.get(triggerName);
const toState = new StateValue(value, this.id);
const isObj = value && value.hasOwnProperty('value');
const isObj = value && Object.hasOwn(value, 'value');
if (!isObj && fromState) {
toState.absorbOptions(fromState.options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ const DEFAULT_NAMESPACE_ID = 'id';
expect(engine.players.length).toEqual(1);
});

it('should read the value from a trigger object whose own key shadows hasOwnProperty', () => {
const engine = makeEngine();

const trig = trigger('myTrigger', [
transition('* => *', [style({height: '0px'}), animate(1000, style({height: '100px'}))]),
]);

registerTrigger(element, engine, trig);

// A bound trigger value in the `{value, params}` object form can come from
// untrusted data (e.g. a parsed JSON payload) and carry an own `hasOwnProperty`
// key that shadows the method. Detecting the object form must not depend on it.
const value = JSON.parse('{"value": "matched", "hasOwnProperty": "x"}');
expect(() => setProperty(element, engine, 'myTrigger', value)).not.toThrow();

engine.flush();
expect(engine.players.length).toEqual(1);
});

it('should throw an error if an animation property without a matching trigger is changed', () => {
const engine = makeEngine();
expect(() => {
Expand Down