mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fix for username regex
This commit is contained in:
parent
5f0c590ca6
commit
372b22aa48
3 changed files with 20 additions and 1 deletions
|
@ -683,7 +683,7 @@ class Site < Sequel::Model
|
|||
end
|
||||
|
||||
def self.valid_username?(username)
|
||||
!username.empty? && username.match(/^[a-zA-Z0-9][a-zA-Z0-9_\-]+[a-zA-Z0-9]$/i)
|
||||
!username.empty? && username.match(/^[a-zA-Z0-9]([a-zA-Z0-9_\-]{0,}[a-zA-Z0-9])?$/i) != nil
|
||||
end
|
||||
|
||||
def self.disposable_email_domains_whitelist
|
||||
|
|
|
@ -25,6 +25,10 @@ describe 'signup' do
|
|||
end
|
||||
|
||||
before do
|
||||
reset_signup
|
||||
end
|
||||
|
||||
def reset_signup
|
||||
Capybara.default_driver = :selenium_chrome_headless_largewindow
|
||||
Capybara.reset_sessions!
|
||||
visit_signup
|
||||
|
@ -107,9 +111,13 @@ describe 'signup' do
|
|||
fill_in 'username', with: '|\|0p|E'
|
||||
click_signup_button
|
||||
_(page).must_have_content 'Usernames can only contain'
|
||||
reset_signup
|
||||
fill_in_valid
|
||||
fill_in 'username', with: 'nope-'
|
||||
click_signup_button
|
||||
_(page).must_have_content 'Usernames can only contain'
|
||||
reset_signup
|
||||
fill_in_valid
|
||||
fill_in 'username', with: '-nope'
|
||||
click_signup_button
|
||||
_(page).must_have_content 'Usernames can only contain'
|
||||
|
|
|
@ -5,6 +5,17 @@ def app
|
|||
end
|
||||
|
||||
describe Site do
|
||||
describe 'username' do
|
||||
it 'only passes valid hostnames for username' do
|
||||
_(Site.valid_username?('|\|0p|E')).must_equal false
|
||||
_(Site.valid_username?('nope-')).must_equal false
|
||||
_(Site.valid_username?('-nope')).must_equal false
|
||||
_(Site.valid_username?('do-pe')).must_equal true
|
||||
_(Site.valid_username?('d')).must_equal true
|
||||
_(Site.valid_username?('do')).must_equal true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'banning' do
|
||||
it 'still makes files available' do
|
||||
site = Fabricate :site
|
||||
|
|
Loading…
Add table
Reference in a new issue