ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

[BUGFIX beta] Negative indices in `positional` args proxy

Open buschtoens opened this issue 5 years ago • 6 comments

In ember-link I had code that potentially accessed a negative index on a positional args proxy, which used to return undefined. Starting with the 3.23.0 beta, this throws an error.

This is because only the upper bound is checked.

buschtoens avatar Nov 16 '20 15:11 buschtoens

Also, we need a test for this behavior (confirming that modifiers,helpers, and components can access args[-1] and get undefined back).

rwjblue avatar Nov 16 '20 15:11 rwjblue

Cool! Let me know on the way forward regarding:

I think it may be better to change convertToInt to return null for negative indices.

I'll update the PR then and add tests. 🧪

buschtoens avatar Nov 16 '20 15:11 buschtoens

Starting with the 3.23.0 beta, this throws an error.

Oh, also, what is the error here?

rwjblue avatar Nov 16 '20 15:11 rwjblue

Uncaught (in promise) TypeError: ref is undefined
    valueForRef reference.js:145
    get
    normalizeLinkParams
    compute
    getValue
    ...

https://github.com/emberjs/ember.js/blob/0f3266c9b83fc9cad53b0a95f1732935d09eaf60/packages/%40ember/-internals/glimmer/lib/utils/args-proxy.ts#L104-L106

https://github.com/glimmerjs/glimmer-vm/blob/022b586405a857afdf59eebfcdae1f51428dc344/packages/%40glimmer/reference/lib/reference.ts#L153

ref is undefined as positional[-1] is undefined.

buschtoens avatar Nov 16 '20 15:11 buschtoens

Cool! Let me know on the way forward regarding:

I think it may be better to change convertToInt to return null for negative indices.

Just chatted with @pzuraq / @krisselden about this, lets do it this way. I think that would look something like:

function convertToInt(prop: number | string | symbol): number | null {
  if (typeof prop === 'symbol') return null;

  const num = Number(prop);

  if (isNaN(num)) return null;

  return num % 1 === 0 && num > -1 ? num : null;
}

Then we just need some tests, and to update the commit message/PR title to [BUGFIX release] since 3.23 has been released.

rwjblue avatar Nov 17 '20 21:11 rwjblue

Is this still relevant?

kategengler avatar Dec 12 '23 16:12 kategengler