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

Fix slash in taxonomies #5675

Merged
merged 5 commits into from
Aug 13, 2016
Merged

Fix slash in taxonomies #5675

merged 5 commits into from
Aug 13, 2016

Conversation

SvanteRichter
Copy link
Contributor

@SvanteRichter SvanteRichter commented Aug 11, 2016

Fixes #5673

In taxonomy slugs we basically allow any character (since we do not slugify them). One way to test this is to add a tag with a bunch of special chars or with a taxonomy like this:

categories:
    name: Categories
    slug: categories
    singular_name: Category
    singular_slug: category
    behaves_like: categories
    options: {'test&%¤': test}

The only character that we cannot use or have is a slash since that denotes a separation of url portions.

This PR removes any slash found in a taxonomy slug (since that's how we do it in record slugs) and shows a warning flash message if a slash is put in a slug in taxonomy.yml.

PRing into 3.0 since this is a bug fix, let me know if I should retarget to 3.1.

@SvanteRichter SvanteRichter changed the title Fix slash in tags Fix slash in taxonomies Aug 11, 2016
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSR-2 on the variable name case.

Also the nesting is a tad aggressive… Does this read better to you on review?

    public function checkTaxonomy()
    {
        foreach ($this->data['taxonomy'] as $key => $taxonomy) {
            if (empty($taxonomy['options']) || !is_array($taxonomy['options'])) {
                continue;
            }

            foreach ($taxonomy['options'] as $optionKey => $optionValue) {
                if (strpos($optionKey, '/') === false) {
                    continue;
                }

                $error = Trans::__(
                    'general.phrase.invalid-taxonomy-slug',
                    ['%taxonomy%' => $key, '%option%' => $optionValue]
                );
                $this->app['logger.flash']->error($error);
            }
        }
    }

@@ -71,6 +71,7 @@ public function before(Request $request, Application $app, $roleRoute = null)
// Sanity checks for doubles in in contenttypes. This has to be done
// here, because the 'translator' classes need to be initialised.
$app['config']->checkConfig();
$app['config']->checkTaxonomy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just flagging for the a.m.

This is not the place to be doing/firing this …

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, where is the right place? I didn't really know where to put it, so I followed the checkConfig way of doing things, and assumed that following established code was the way to go until we actually get to the config refactor. That way it's more predictable, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure yet, was mid-wife-night and just noticed this walking past my screen … let me look post- ☕

Copy link
Contributor

@GwendolenLynch GwendolenLynch Aug 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK … so after looking at it, and thinking about it … probably best for now to put that at the end of checkConfig() as that is one of the things on my 🔥 list for the 3.2 exception/request work.

Short version is that we're checking on every request the configuration of the configuration … ConfigCeption … that is already cached … if it is cached, then we know it's already passed checks.

Copy link
Contributor

@GwendolenLynch GwendolenLynch Aug 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also moving the call means we can make that function private and not expose another API

Copy link
Contributor

@GwendolenLynch GwendolenLynch Aug 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.f. master...GawainLynch:hotfix/config-check-request

Note that branch is for master (3.2), but you should get the idea on direction.

@GwendolenLynch
Copy link
Contributor

Green it is going, it is … :shipit:

@GwendolenLynch GwendolenLynch merged commit a829cce into bolt:release/3.0 Aug 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants