Skip to content

Incorrect regex in URLPathVersioning documentation #3638

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

Closed
bluetech opened this issue Nov 15, 2015 · 5 comments
Closed

Incorrect regex in URLPathVersioning documentation #3638

bluetech opened this issue Nov 15, 2015 · 5 comments

Comments

@bluetech
Copy link
Contributor

Version: 3.3.1

The documentation for versioning.URLPathVersioning (both the docstring and the API guide) provides the following example for the URL regex: r'^(?P<version>[v1|v2]+)/bookings/$'. Unless I am misunderstanding, I think that [v1|v2] is supposed to be (v1|v2), and that the + should be removed. Also, I am not sure whether it is customary to add a mandatory trailing slash or not.

(From git blame I see the regex was changed to the above in pull request #3037).

@tomchristie
Copy link
Member

I think that [v1|v2] is supposed to be (v1|v2), and that the + should be removed.

Correct and correct.

Also, I am not sure whether it is customary to add a mandatory trailing slash or not.

It's not mandatory (either would be valid) but I would like to leave the style as it is.

@jpadilla
Copy link
Member

Both options seem to work fine. Can anyone explain the difference between r'^(?P<version>[v1|v2]+)/bookings/$' and r'^(?P<version>(v1|v2))/bookings/$'?

@xordoquy
Copy link
Collaborator

[] is for set of characters which means [abc] will match 'a', 'b', or 'c'.
() is for groups which takes the content as a whole.

@jpadilla
Copy link
Member

@xordoquy got it, thanks! @bluetech want to put a PR together for this?

pt247 added a commit to pt247/django-rest-framework that referenced this issue Nov 26, 2015
jpadilla added a commit that referenced this issue Nov 26, 2015
Fix for Incorrect regex in URLPathVersioning documentation #3638
@jpadilla
Copy link
Member

Closed by #3675

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

4 participants