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
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
4 changes: 3 additions & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2737,13 +2737,15 @@ PDF document represented as a Base64-encoded string.
params: browsingContext.PrintParameters
}

browsingContext.PageRange = text .regexp "^(?:[0-9]+)?(?:-(?:[0-9]+)?)?$"
jimevans marked this conversation as resolved.
Show resolved Hide resolved
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).


browsingContext.PrintParameters = {
context: browsingContext.BrowsingContext,
? background: bool .default false,
? margin: browsingContext.PrintMarginParameters,
? orientation: ("portrait" / "landscape") .default "portrait",
? page: browsingContext.PrintPageParameters,
? pageRanges: [*(js-uint / text)],
? pageRanges: [*(js-uint / browsingContext.PageRange )],
? scale: (0.1..2.0) .default 1.0,
? shrinkToFit: bool .default true,
}
Expand Down