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

Add regular expression for page ranges #476

Closed
wants to merge 1 commit into from
Closed

Conversation

jrandolf-2
Copy link
Contributor

@jrandolf-2 jrandolf-2 commented Jul 6, 2023

index.bs Outdated Show resolved Hide resolved
index.bs Show resolved Hide resolved
@@ -2737,13 +2737,15 @@ PDF document represented as a Base64-encoded string.
params: browsingContext.PrintParameters
}

browsingContext.PageRange = text .regexp "^(?:[0-9]+)?(?:-(?:[0-9]+)?)?$"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I'm nervous about introducing regex into the spec, because I suspect in practice there are enough differences between dialects that they are likely to lead to interop problems.

In particular the regexp above is wrong per spec (though probably works OK in a js implementation) because CDDL specifies that it follows https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#regexs. That implicitly anchors expressions, so ^ and $ match literals rather than start/end of the string. I also don't think it has capture groups, so I'm not sure what ?: would actually do (I think the : would match itself, but the ? might be a syntax error? Not sure; I've literally never looked at this spec before).

Given that, I think we'd either have to intentionally violate the CDDL spec and pick a different syntax (e.g. ECMAScript, although that itself might not work for code generation in languages with different regex implementations e.g. Go or Rust), or use the XSD format and rely on everyone implementing a conversion into an actual implemented regex syntax. Or just not use regex and avoid the entire problem, at the cost of having to write a bit of extra code whenever there's string parsing. Which is hopefully "almost never", since we can generally choose to use structured data instead.

So I think my preference is to drop this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be in favor of the universal minimal syntax. Based on the XSD, it looks like that format is the minimal.

That said, how about we change page ranges to use (* [js-uint,js-uint] | js-uint)? I think we can avoid this all together if we just allowed this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string possibility comes from webdriver classic: https://w3c.github.io/webdriver/#print

I believe we need to be permissive in order to keep compatibility with it, otherwise it would be a regression/downgrade.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(* [js-uint,js-uint] | js-uint) would also be wrong because one can omit the ends of the range. So we'd have to allow null in either the first or second position, but not both. I don't think this would be incompatible with the goal of having classic be implementable on top of BiDi, but it would add some complexity. The main argument against using the fully array-based syntax is that it's trickier to write by hand (and less like what you write in the print dialog).

Copy link
Member

@thiagowfx thiagowfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing approval given @jgraham's comment.

@jrandolf-2
Copy link
Contributor Author

Closing in favor of #481

@jrandolf-2 jrandolf-2 closed this Jul 7, 2023
@jrandolf-2 jrandolf-2 deleted the jrandolf/regex branch July 7, 2023 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants