Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow User handles to start with numbers. #532

Closed
wants to merge 1 commit into from

2 participants

@1337807

The regex that validates user handles disallows a starting number, dash or underscore. I aspire to give all numbered users an opportunity to be seen as equals amongst their peers, but I'm happy to continue discriminating against the underscored and dashed.

@1337807 1337807 Allow User handles to start with numbers.
The validation for a User now allows numbers, though dashes and underscores are
still not allowed as starting characters. User tests reflect the new behavior.
6ddda1f
@sferik
Owner

We can't merge this because it creates a conflict with existing profile URLs.

Users that don't have handles (for example, #45159) are identified by their users IDs. We also use user IDs as aliases, even if a user has a handle (for example, #1).

If we allowed handles that began with number, someone could register a numeric handle (e.g. 45159 or 1), which would collide with these existing URLs.

Thanks for submitting this anyway.

@sferik sferik closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 14, 2013
  1. @1337807

    Allow User handles to start with numbers.

    1337807 authored
    The validation for a User now allows numbers, though dashes and underscores are
    still not allowed as starting characters. User tests reflect the new behavior.
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +1 −1  app/models/user.rb
  2. +3 −1 test/unit/user_test.rb
View
2  app/models/user.rb
@@ -18,7 +18,7 @@ class User < ActiveRecord::Base
before_create :generate_api_key
validates_uniqueness_of :handle, :allow_nil => true
- validates_format_of :handle, :with => /\A[A-Za-z][A-Za-z_\-0-9]*\z/, :allow_nil => true
+ validates_format_of :handle, :with => /\A[A-Za-z0-9][A-Za-z_\-0-9]*\z/, :allow_nil => true
validates_length_of :handle, :within => 3..15, :allow_nil => true
def self.authenticate(who, password)
View
4 test/unit/user_test.rb
@@ -10,7 +10,9 @@ class UserTest < ActiveSupport::TestCase
context "validations" do
context "handle" do
should allow_value("CapsLOCK").for(:handle)
- should_not allow_value("1abcde").for(:handle)
+ should allow_value("1337807").for(:handle)
+ should_not allow_value("_abcde").for(:handle)
+ should_not allow_value("-abcde").for(:handle)
should_not allow_value("abc^%def").for(:handle)
should_not allow_value("abc\n<script>bad").for(:handle)
Something went wrong with that request. Please try again.