OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
guard against illegal wiki page versions
ulfertse703f6b03a98
diff --git a/app/helpers/wiki_pages/at_version.rb b/app/helpers/wiki_pages/at_version.rbindex 651f72c2d98..d18bdaa140f 100644--- a/app/helpers/wiki_pages/at_version.rb+++ b/app/helpers/wiki_pages/at_version.rb@@ -39,7 +39,7 @@ class WikiPages::AtVersion < SimpleDelegatordef initialize(wiki_page, version = nil)super(wiki_page)- self.version = (version || wiki_page.version).to_i+ self.version = (version || wiki_page.version).to_i.clamp(1, wiki_page.version)self.latest_version = wiki_page.versionenddiff --git a/spec/helpers/wiki_pages/at_version_spec.rb b/spec/helpers/wiki_pages/at_version_spec.rbindex 92b7322af0a..6c31d4f3cf6 100644--- a/spec/helpers/wiki_pages/at_version_spec.rb+++ b/spec/helpers/wiki_pages/at_version_spec.rb@@ -101,6 +101,24 @@ describe WikiPages::AtVersion do.to eq second_journal_userendend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is the last journal`s user' do+ expect(page_at_version.author)+ .to eq second_journal_user+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is the first journal`s user' do+ expect(page_at_version.author)+ .to eq first_journal_user+ end+ endenddescribe '#journals' do@@ -130,6 +148,24 @@ describe WikiPages::AtVersion do.to contain_exactly(first_journal, second_journal)endend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is the full set of journals' do+ expect(page_at_version.journals)+ .to contain_exactly(first_journal, second_journal)+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is only the first journal' do+ expect(page_at_version.journals)+ .to contain_exactly(first_journal)+ end+ endenddescribe '#lock_version' do@@ -159,6 +195,24 @@ describe WikiPages::AtVersion do.to eq second_journal.versionendend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is the last journals`s version' do+ expect(page_at_version.lock_version)+ .to eq second_journal.version+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is the first journals`s version' do+ expect(page_at_version.lock_version)+ .to eq first_journal.version+ end+ endenddescribe '#updated_at' do@@ -188,6 +242,24 @@ describe WikiPages::AtVersion do.to eq second_journal.updated_atendend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is the last journals`s updated_at' do+ expect(page_at_version.updated_at)+ .to eq second_journal.updated_at+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is the first journals`s updated_at' do+ expect(page_at_version.updated_at)+ .to eq first_journal.updated_at+ end+ endenddescribe '#version' do@@ -208,6 +280,24 @@ describe WikiPages::AtVersion do.to eq versionendend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is the highest possible version' do+ expect(page_at_version.version)+ .to eq 2+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is first version' do+ expect(page_at_version.version)+ .to eq 1+ end+ endenddescribe '#latest_version' do@@ -257,6 +347,24 @@ describe WikiPages::AtVersion do.to eq second_journal_textendend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is the last journals`s text' do+ expect(page_at_version.text)+ .to eq second_journal_text+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is the first journals`s text' do+ expect(page_at_version.text)+ .to eq first_journal_text+ end+ endenddescribe '#readonly?' do@@ -286,6 +394,24 @@ describe WikiPages::AtVersion do.not_to be_readonlyendend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is false' do+ expect(page_at_version)+ .not_to be_readonly+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is true' do+ expect(page_at_version)+ .to be_readonly+ end+ endenddescribe '#current_version?' do@@ -315,6 +441,24 @@ describe WikiPages::AtVersion do.to be_current_versionendend++ context 'with the version being larger then the current one' do+ let(:version) { 3 }++ it 'is true' do+ expect(page_at_version)+ .to be_current_version+ end+ end++ context 'with the version being less then 1' do+ let(:version) { 0 }++ it 'is true' do+ expect(page_at_version)+ .not_to be_current_version+ end+ endenddescribe '#object' do