Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping an item while iterating is undefined #768

Open
SuperSonicHub1 opened this issue May 3, 2023 · 1 comment
Open

Skipping an item while iterating is undefined #768

SuperSonicHub1 opened this issue May 3, 2023 · 1 comment
Labels
clarification Standard could be clearer

Comments

@SuperSonicHub1
Copy link

The URL Standard, when parsing percent-encoded bytes while percent-decoding, makes use of an undefined byte sequence method "skip" on L430. It seems to get a variable number of items from an iterator and immediately dispose of them, like in the following Python code:

def skip(iterator: iterator, n: int):
    for i in range(n):
        next(iterator)

It would seem that the byte sequence input holds a reference to the iterator instance, as implied by the language Skip the next two bytes in <var>input</var>.

As the creation of an iterator is currently implicit in the Infra Standard, I believe explicitly defining a generic iterator data structure, implementing the "skip" method for it, and changing all "iterate" and "for each" definitions to use iterators would be the best course of action. If this were to go through, the URL Standard would then have to wait for whatwg/infra#571 to be resolved.

An initial concern with the approach described above is the edge case of handling a skip on an empty iterator: would we throw an exception or have skipping be a no-op?

On the other hand, this one step in the URL Standard is the only place where this method is used; if "skip" were to be left undefined, it would then be on the URL Standard to revise the percent-encoding algorithm.

Copy of whatwg/infra#572

@annevk annevk added the clarification Standard could be clearer label May 3, 2023
@TimothyGu
Copy link
Member

TimothyGu commented May 4, 2023

In this case, "skip" can never be "called" on an empty iterator, since step 2.3.3 only occurs if byte is 0x25 (%) and the next two bytes after byte in input are in the ranges /[0-9a-fA-F]/. As such, I believe there's no ambiguity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer
Development

No branches or pull requests

3 participants