diff --git a/app/models/web.rb b/app/models/web.rb index 453f84cb..8b54ca52 100644 --- a/app/models/web.rb +++ b/app/models/web.rb @@ -5,12 +5,15 @@ require "wiki_words" require "zip/zip" class Web - attr_accessor :name, :address, :password, :markup, :color, :safe_mode, :pages + attr_accessor :name, :password, :markup, :color, :safe_mode, :pages attr_accessor :additional_style, :published, :brackets_only, :count_pages, :allow_uploads attr_accessor :max_upload_size + + attr_reader :address def initialize(parent_wiki, name, address, password = nil) - @wiki, @name, @address, @password = parent_wiki, name, address, password + self.address = address + @wiki, @name, @password = parent_wiki, name, password # default values @markup = :textile @@ -30,6 +33,13 @@ class Web @pages[page.name] = page end + def address=(the_address) + if the_address != CGI.escape(the_address) + raise Instiki::ValidationError.new("Web name should contain only valid URI characters") + end + @address = the_address + end + def authors select.authors end diff --git a/test/test_helper.rb b/test/test_helper.rb index 50992837..f7c949f4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,7 @@ ENV['RAILS_ENV'] = 'test' require File.expand_path(File.dirname(__FILE__) + '/../config/environment') require 'application' require 'test/unit' +require 'breakpoint' require 'action_controller/test_process' # Uncomment this variable to have assert_success check that response bodies are valid XML diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index bbcf6b2d..e120a56f 100755 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -119,6 +119,12 @@ class WebTest < Test::Unit::TestCase assert_equal 100, web.max_upload_size end + def test_initialize_invalid_name + wiki_stub = Object.new + assert_raises(Instiki::ValidationError) { + Web.new(wiki_stub, 'Wiki2', "wiki\234", '123') + } + end private