summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-04-02 17:05:58 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-04-02 17:05:58 +0200
commit19e6c340910989718e703eff34fb563c56b71b32 (patch)
tree11fa28c0c2f90cdb12812400ff739f32c6b1872f /sonar-server
parentc8bf78cb40dd823b7bfa32c4243c79efc0c9cc1c (diff)
downloadsonarqube-19e6c340910989718e703eff34fb563c56b71b32.tar.gz
sonarqube-19e6c340910989718e703eff34fb563c56b71b32.zip
SONAR-4083 Remove whitespace in metric id
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/metrics_controller.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/metrics_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/metrics_controller.rb
index 3f849a5e449..9c5e0357794 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/metrics_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/metrics_controller.rb
@@ -45,8 +45,10 @@ class Api::MetricsController < Api::RestController
def create
bad_request('Name is required') unless params[:name].present?
+ metric_name = params[:name].downcase.gsub(/\s/, '_')[0..59]
+ metric_id_as_text = params[:id].downcase.gsub(/\s/, '_')[0..59] if params[:id] && params[:id].to_i > 0
- metric_test = Metric.first(:conditions => ['name=? OR id=?', params[:id], params[:id].to_i])
+ metric_test = Metric.first(:conditions => ['name=? OR id=?', metric_id_as_text, params[:id].to_i])
exist_and_is_disable = !metric_test.nil? && !metric_test.enabled?
if exist_and_is_disable
@@ -56,9 +58,9 @@ class Api::MetricsController < Api::RestController
end
begin
- metric.attributes = params.merge({:name => params[:id], :short_name => params[:name]})
+ metric.attributes = params.merge({:name => metric_id_as_text, :short_name => metric_name})
if metric.short_name(false)
- metric.name = metric.short_name(false).downcase.gsub(/\s/, '_')[0..59] unless params[:id]
+ metric.name = metric.short_name(false) unless metric_id_as_text
end
metric.origin = Metric::ORIGIN_WS
metric.user_managed = true