Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reuse 'validate_opm_name' to parse passed parameter that is used to g…

…et the name for maintainer list.
  • Loading branch information...
commit 70d5b1a7a1c5928319f597e7acc510057572af21 1 parent 5836b69
@reneeb authored
View
14 lib/OTRS/OPR/Web/Author/Package.pm
@@ -223,8 +223,11 @@ sub edit_maintainer : Permission( 'author' ) {
#return $self->forgot_password( %uppercase );
}
- my ($package_name, $package_version) = split /\-/, $self->param( 'id' );
- $package_name = $self->schema->resultset('opr_package_names')->find({ package_name => $package_name });
+
+ my $id = $self->param( 'id' );
+ my ($parsed_name, $package_version) = OTRS::OPR::Web::Utils->validate_opm_name( $id, 1 );
+
+ my $package_name = $self->schema->resultset('opr_package_names')->find({ package_name => $parsed_name });
my $name_id = $package_name->get_column("name_id");
if ($params{'add'}) {
@@ -292,7 +295,8 @@ sub unpublish_comment : Permission( 'author' ) {
sub comments : Permission( 'author' ) {
my ($self) = @_;
- my ($package_name, $package_version) = split /\-/, $self->param( 'id' );
+ my $id = $self->param( 'id' );
+ my ($package_name, $package_version) = OTRS::OPR::Web::Utils->validate_opm_name( $id, 1 );
my @packages = (); # all packages of author OR the single one requested
my @comments = ();
@@ -335,7 +339,9 @@ sub comments : Permission( 'author' ) {
sub maintainer : Permission( 'author' ) {
my ($self) = @_;
- my ($package_name, $package_version) = split /\-/, $self->param( 'id' );
+ my $id = $self->param( 'id' );
+ my ($package_name, $package_version) = OTRS::OPR::Web::Utils->validate_opm_name( $id, 1 );
+
my $package = OTRS::OPR::DAO::Package->new(
package_name => $package_name,
version => $package_version,
View
12 lib/OTRS/OPR/Web/Utils.pm
@@ -132,13 +132,19 @@ sub time_to_date {
}
sub validate_opm_name {
- my ($class,$file) = @_;
+ my ($class,$file,$without_suffix) = @_;
my ($basename) = $file =~ m{ \A .*? ([^\\\/]+) \z }xms;
+ my $suffix = '(\.opm)';
+
+ if ( $without_suffix ) {
+ $suffix = '';
+ }
+
my $success = $basename =~ m{
\A
- ([\w-]+?) # filename
+ ([\w\s-]+?) # filename
(?: # begin version
-( # dash
\d+ # major number of version
@@ -146,7 +152,7 @@ sub validate_opm_name {
(?:\.\d+)? # optional patch number of version
) # version
)? # version is optional
- (\.opm) # file suffix
+ $suffix
\z # string end
}xms;
View
42 t/000_001_web_app_utils.t
@@ -4,7 +4,7 @@ use strict;
use warnings;
use File::Basename;
use File::Spec;
-use Test::More tests => 49;
+use Test::More tests => 67;
my $dir;
my $lib;
@@ -373,5 +373,45 @@ SKIP: {
my $success = OTRS::OPR::Web::Utils->validate_opm_name( $name );
ok !$success, "$name is invalid";
}
+
+
+
+ my %valid_without_suffix = (
+ 'DashboardMOTDPlus-0.1.1' => {
+ package => 'DashboardMOTDPlus',
+ version => '0.1.1',
+ },
+ 'Out-of-Office-0.1' => {
+ package => 'Out-of-Office',
+ version => '0.1',
+ },
+ 'TicketTemplate-1' => {
+ package => 'TicketTemplate',
+ version => '1',
+ },
+ 'Test' => {
+ package => 'Test',
+ version => undef,
+ },
+ '/Dashboard2' => {
+ package => 'Dashboard2',
+ version => undef,
+ },
+ '/test/TicketTest-0.1.1' => {
+ package => 'TicketTest',
+ version => '0.1.1',
+ },
+ );
+
+
+
+ for my $name ( keys %valid_without_suffix ) {
+ my @info = OTRS::OPR::Web::Utils->validate_opm_name( $name, 1 );
+ ok scalar( @info ), "$name is valid";
+
+ my $check = $valid_without_suffix{$name};
+ is $info[0], $check->{package}, 'package name correctly parsed - ' . $check->{package} . ' - without suffix';
+ is $info[1], $check->{version}, 'version correctly parsed - ' . ( defined $check->{version} ? $check->{version} : '<undef>' ) . ' - without suffix';
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.