Problem/Motivation

If a pattern ends with whitespace (eg. by an incorrect copy-paste including a TAB character), it's accepted – but the generated alias will not work.

Proposed resolution

Don't allow the patterns ending with whitespace.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Boobaa created an issue. See original summary.

rahul.nahar001’s picture

Hi @Boobaa,

Yes, you are right for strong URL we need to validate patterns not ending with whitespace.
I have created a patch for fixed this bug.

Thanks
Rahul Nahar

Boobaa’s picture

  1. +++ b/pathauto.module
    @@ -195,6 +195,10 @@ function pathauto_pattern_validate($element, FormStateInterface $form_state) {
    +    ¶
    

    Trailing space.

  2. +++ b/pathauto.module
    @@ -195,6 +195,10 @@ function pathauto_pattern_validate($element, FormStateInterface $form_state) {
    +    if(ereg('[ \f\t\v]+$', $element['#value'])){
    

    Coding standards says if ( – ie. there should be a space between if and the parenthesis.

  3. +++ b/pathauto.module
    @@ -195,6 +195,10 @@ function pathauto_pattern_validate($element, FormStateInterface $form_state) {
    +    }    ¶
    

    Trailing space.

And some tests would be more than welcome.

rahul.nahar001’s picture

Boobaa’s picture

  1. +++ b/pathauto.module
    @@ -195,6 +195,10 @@ function pathauto_pattern_validate($element, FormStateInterface $form_state) {
    +    if (ereg('[ \f\t\v]+$', $element['#value'])) {
    

    ereg() is deprecated as of PHP 5.3.0. Please use preg_match() instead.

  2. +++ b/pathauto.module
    @@ -195,6 +195,10 @@ function pathauto_pattern_validate($element, FormStateInterface $form_state) {
    +       $form_state->setError($element, t('The %element-title don\'t allow the patterns ending with whitespace.', array('%element-title' => $title)));
    

    Too much indentation. Use "doesn't" instead of "don't".

Some automated tests would be needed, too.

Berdir’s picture

Status: Active » Needs work
rahul.nahar001’s picture

Hi,
Please find updated patch file.
I am working on to create automated test case.

Thanks

Dinesh18’s picture

I have applied the patch and it is working as expected. It is throwing an error if there is a trailing white space.

Dinesh18’s picture

Status: Active » Needs review

Changed status to Needs Review

The last submitted patch, 2: pathauto-dont_accept_whitespace_in_patterns-2818273-1.patch, failed testing.

The last submitted patch, 2: pathauto-dont_accept_whitespace_in_patterns-2818273-1.patch, failed testing.

The last submitted patch, 4: pathauto-dont_accept_whitespace_in_patterns-2818273-4.patch, failed testing.

The last submitted patch, 4: pathauto-dont_accept_whitespace_in_patterns-2818273-4.patch, failed testing.

naiduharish’s picture

This Patch Works as expected !!

rahul.nahar001’s picture

Hi @Boobaa,

Please find updated patch file with the automated test case.

Berdir’s picture

Status: Needs review » Fixed

Thanks, committed.

LpSolit’s picture

Wouldn't it be better to silently remove extra whitespaces instead of throwing an error?

Berdir’s picture

Not sure, whould have been possible as well. You could provide a patch for that in a follow-up issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.