I am pretty sure commas and semicolons are not supported in the ID tag, but semicolons and commas will still end up in the tag.

Here is the case where this happens to me:
I have a radio button text widget.
In the Allowed Value List, I have a line similar to the following:
Heres is a valid radio button item; however, the CSS ID tag will put a semicolon and command in the id

Comments

thekevinday’s picture

Oops, I prematurely hit Save.

The end result CSS ID would be:
Heres-is-a-valid-radio-button-item;-however,-the-CSS-ID-tag-will-put-a-semicolon-and-command-in-the-id

This is invalid as far as I can tell and cannot be properly modified via CSS.

I also discovered that other symbols such as the period ., parenthesis (), and so on.. will also end up in the ID tag when it should not.

thekevinday’s picture

Title: Semicolons and Commas end up in CSS ID tag » Invalid characters end up in CSS ID tag, form_id_clean() does not handle enough cases
Project: Content Construction Kit (CCK) » Drupal core
Version: 6.x-2.6 » 6.16
Component: Usability » forms system
Status: Active » Needs review
StatusFileSize
new539 bytes

After doing some searching around in the code, I could not find a place in CCK where this is being set.

Instead, I looked into Drupal core and found the function form_id_clean: http://api.drupal.org/api/function/form_clean_id/6

The relevant line is:

<?php
$id = str_replace(array('][', '_', ' '), '-', $id);
?>

That is far too few cases.

Instead, something like the following could be used:

<?php
$id = str_replace(array('][', '_', ' ', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', '[', '{', '}', ']', '|', '\\', ';', ':', '\'', '"', '<', ',', '>', '.', '?', '/'), '-', $id);
?>

But the next problem here is different languages.
So, I decided that a regular expression would work better as this allows for more language independent symbol replacements:

<?php
$id = str_replace(array('][', '_', ' '), '-', $id);
$id = preg_replace('/\W/i', '-', $id);
?>

I left the existing str_replace for two reasons:
1) the underscore symbol '_' is considered a Word character and will not get replaced by the given preg_replace function
2) I don't know what is going on with the '][' case.

I have a patch for review that fixes this case.

Status: Needs review » Needs work

The last submitted patch, drupal-6.16-better_css_form_clean_id-1.patch, failed testing.

sreynen’s picture

Status: Needs work » Needs review
StatusFileSize
new703 bytes

This patch simply backports the cleaning code from D7's drupal_clean_css_identifier.

Status: Needs review » Needs work

The last submitted patch, form_clean_id.patch, failed testing.

thekevinday’s picture

Version: 6.16 » 6.19

Unfortunately the patch you provided breaks things like views module's Live preview.

My patch works without any problems that I have noticed.

As far as your patch, I did a diff between a working views view and your backport shows that:
Before your patch the relevant view html looks like: edit-live-preview
After your patch the relevant view html looks like: edit-live_preview

sreynen’s picture

StatusFileSize
new677 bytes

@thekevinday, I was thinking the work in D7 happened after your patch and likely received more attention so that was the best place to pick this up again. I think I put the new line in the wrong place on the last patch.

sreynen’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, form_clean_id.patch, failed testing.

thekevinday’s picture

Status: Needs work » Reviewed & tested by the community

This latest one is working so far.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Hm, looking at http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_cl... it seems to have other differences as well. Like [ converted to - but ] removed (which is not the same as converting ][ to -). Also, it has / converted to -. Finally, it has some valuable docs, that is really lacking here. Let's not introduce a list of cryptic looking regex items without explaining them.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.