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

Should error for <span> that fails to xref #33

Closed
zcorpan opened this issue Nov 25, 2016 · 12 comments
Closed

Should error for <span> that fails to xref #33

zcorpan opened this issue Nov 25, 2016 · 12 comments
Assignees

Comments

@zcorpan
Copy link
Member

zcorpan commented Nov 25, 2016

<span>no such term</span> should be an error.

@annevk
Copy link
Member

annevk commented Nov 25, 2016

So the solution is in changing line 454. However, I cannot get

if (Element.HasAttribute(kCrossRefAttribute) or Element.IsIdentity(nsHTML, eCode) or (Element.IsIdentity(nsHTML, eSpan) and Element.Attributes.Count = 0)) then

or variants to compile. I'm not sure what's wrong since Attributes.Count is compared as a number elsewhere just fine.

@Hixie can you help?

(We need to ignore <span> elements with attributes, due to classes and lang attributes and such. And I don't think we want to exclude those attributes explicitly.)

annevk added a commit to whatwg/html that referenced this issue Nov 25, 2016
Found while working on whatwg/wattsi#33.

I also took the liberty to remove erroneous title attributes.

#2097 is follow-up.
@sideshowbarker
Copy link
Contributor

I remember running into a similar problem before.

To fix it I think you need to do this (wrapped for readability):

if (Element.HasAttribute(kCrossRefAttribute) or Element.IsIdentity(nsHTML, eCode)
    or (Element.IsIdentity(nsHTML, eSpan) and (Element.Attributes.Count = 0))) then

That is, with parens in "and (Element.Attributes.Count = 0)".

Otherwise without the parens, if there’s a bare identifier after the and, I think in Pascal the order of evaluation is, the compiler tries to evaluate that identifier on its own as a boolean. And it finds Element.Attributes.Count is not a boolean, so it bails.

So I think in Pascal to make a compiler evaluate the Element.Attributes.Count = 0 expression first, as whole—and not prematurely evaluate Element.Attributes.Count on its own—parens are needed.

@annevk
Copy link
Member

annevk commented Nov 25, 2016

I tried that, same or nearly the same result unfortunately.

@annevk
Copy link
Member

annevk commented Nov 25, 2016

To be clear, that makes it compile, but running it results in:

EAccessViolation exception: Access violation
Backtrace:
  $00019C49
  $000172BC
  $0001408E
  $0001182D
  $00025F0B

annevk added a commit that referenced this issue Nov 25, 2016
Only do this when the <span> has no attributes as using the
lang/class/id attributes should continue to be okay.

Fixes #33.
@annevk
Copy link
Member

annevk commented Nov 25, 2016

The overall problem was that an Element without attributes never gets Attributes assigned. So the correct way would be (not Assigned(Element.Attributes)).

@Hixie
Copy link
Member

Hixie commented Nov 25, 2016

Isn't there a HasAttributes?

@annevk
Copy link
Member

annevk commented Nov 25, 2016

I don't think so. At least your code also does this Assigned trick in a number of places.

@sideshowbarker
Copy link
Contributor

(meta point) I guess we could add a HasAttributes that returns boolean, but even if we did I wonder what other need we’d ever end up having for it.

The need right now is that we want to:

A. identify and report cases of xref spans like "<span>Clear regions that cover the pixels</span>" that don’t have any corresponding dfn in the source or "the <span>XML syntax</span>" which to match the right dfn should be <span>the XML syntax</span> or <span data-x="the XML syntax">XML syntax</span>
B. ignore non-xref spans like "<span class="note">…</span>"

So starting by only checking for span elements that have no attributes, we can skip the B instances.

But other than the span-for-xref case I can’t think of any similar uses of particular elements in the source where for some reason we might want to find instances of them that have no attributes at all.

@annevk
Copy link
Member

annevk commented Nov 26, 2016

In current tip of tree, lines 241 and 1447 also do this check, both related to attribute counting. I'm not sure at what point it's worth having an abstraction, but I don't think this is quite it. (And if anything, this might more argue for some counting abstraction.)

@zcorpan
Copy link
Member Author

zcorpan commented Nov 28, 2016

So something like this will happily be converted to a link:

<span class="">The XML syntax</span>

Maybe we should switch to <a> instead?

zcorpan pushed a commit to whatwg/html that referenced this issue Nov 28, 2016
Found while working on whatwg/wattsi#33.

I also took the liberty to remove erroneous title attributes.

#2097 is follow-up.
@annevk
Copy link
Member

annevk commented Nov 28, 2016

True, we could probably exclude <span> elements that have attributes that are not data-x or switch to <a>. Seems like a follow-up though given the work involved and the PR provided has actually helped spotting a number of errors.

@zcorpan
Copy link
Member Author

zcorpan commented Nov 28, 2016

Yes, agreed. Filed #38

annevk added a commit that referenced this issue Nov 28, 2016
Only do this when the <span> has no attributes as using the
lang/class/id attributes should continue to be okay.

Fixes #33.
alice pushed a commit to alice/html that referenced this issue Jan 8, 2019
Found while working on whatwg/wattsi#33.

I also took the liberty to remove erroneous title attributes.

whatwg#2097 is follow-up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants