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

anchor-as-name: false replaces name attribute of a form tag with id attribute #571

Closed
suchafreak opened this issue Jun 29, 2017 · 7 comments

Comments

@suchafreak
Copy link

suchafreak commented Jun 29, 2017

Given this markup:

<!doctype html>
<html lang="de-CH">
<head>
  <meta charset="UTF-8"/>
  <title>Form with name attribute</title>
</head>
<body>
<form name="test"></form>
</body>

and anchor-as-name set to false tidy returns this:


<html lang="de-CH">
<head>
<meta charset="UTF-8">
<title>Form with name attribute</title>
</head>
<body>
<form id="test"></form>
</body>
</html>

I would expect tidy to not alter the form tag.
Instead of
<form id="test"></form>

I would expect the original

<form name="test"></form>

The form tag is not an anchor element and should therefore be unaffected by anchor-as-name

@geoffmcl
Copy link
Contributor

geoffmcl commented Jul 1, 2017

@suchafreak thank you for your issue...

Well, it seems the addition of a id attribute when tidy finds a name attribute, in an anchor, has been the action of tidy for a long, LONG time... not that that in itself means anything...

But not quite sure why that includes <form>, but it does...

And then --anchor-as-name false option just removes the name attribute, as the docs implies...

The form tag is not an anchor element and should therefore be unaffected by anchor-as-name

As you suggest, the first thing seems to be to understand why <form> got included. In tests it does not seem to act as an anchor, so why is it changed, but not say <p name="para">Para</p>...

But of course name is not a valid attribute of <p>... is that it, all elements that support the name attribute are effected?

Will do some research... any pointers in the code or docs appreciated... thanks...

@geoffmcl geoffmcl added this to the 5.5 milestone Jul 1, 2017
@suchafreak
Copy link
Author

Thanks, @geoffmcl for your reply.

Further tests with forms show that the name attribute in input and select tags is left alone, which is good, because submitting form data wouldn't work otherwise.

I will do some further tests with tags that support the name attribute and report my findings here.

@balthisar
Copy link
Member

@suchafreak, is there still an issue, or can we close this out?

@suchafreak
Copy link
Author

@balthisar: Sorry for my late answer.
In my opinion this behavior is wrong.

Tidy should leave the form-tag alone. It can cause problems with scripts that rely on the name tag to be present. And rewriting scripts is not always an option, as in our case, were users are free to add their own scripts to a web page the create using our tool.

HTH
Cheers

@geoffmcl
Copy link
Contributor

geoffmcl commented Dec 5, 2017

Need to re-look at what is desired/required here, but meantime moving out the milestone...

@geoffmcl geoffmcl modified the milestones: 5.5, 5.7 Dec 5, 2017
@ghost
Copy link

ghost commented May 14, 2018

@suchafreak, according to the docs for --anchor-as-name,

If set to no any existing name attribute is removed if an id attribute exists or has been added.

(I added the italics at the end.)

We can see from your first post that no id attribute exists on your form element at the moment of being input to tidy, but did you have any options enabled that could have added that id attribute?

If so, then this explains the behaviour you observed. If not, then I agree that you have encountered a bug in tidy, in its documentation, or in both.

@geoffmcl
Copy link
Contributor

Update 20210222: years later...

@suchafreak, I have just carefully re-read this issue, and did some more debug testing... and, sorry, still can not find any issue...

The issue title - anchor-as-name: false replaces name attribute of a form tag with id attribute - is not exactly the correct wording! Tidy does not replace name with id!! To explain -

In the API tidyCleanAndRepair, internal tidyDocCleanAndRepair, in the internal service TY_(FixAnchors), on finding a name="test" attribute, tidy will either adjust any id attribute to the same value, or, in absence of an existing id attribute, will add one. So at this point your input <form name="test"> becomes <form name="test" id="test">. No replacment, just a simple addition.

Now, through your config, anchor-as-name: false, enum TidyAnchorAsName, you have requested tidy to remove the name attribute. So in that same internal service, TY_(FixAnchors), tidy will remove the name attribute. Hence the now <form name="test" id="test">, will become <form id="test">... the final output...

I can understand that you could think that there is some replacement, but as you can see from the above, it is, in fact, two separate steps - An addition of the id, and then a deletion, by the config, of the name...

And @ghost, that is more, or less, what the docs say - the name attributeis remove, whether it isexisting**or**has been added, provided an idattribute exists - could maybe also addor has been added` - so I find no big fault in the docs...

Feel free to suggest any improvement... the docs can always be expanded... that should be a new issue...

So, at present, I can not find any issue here that needs to be fixed, so closing this...

Look forward to any further feedback, if I got something wrong, or misunderstand, etc... thanks..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants