Fix validation issue of Get url maximum length

hbywoo лет %!s(int64=10): %!d(string=назад)
Родитель
Сommit
3abc91956e
1 измененных файлов с 9 добавлено и 3 удалено
  1. 9 3
      app/helpers/dot_helper.rb

+ 9 - 3
app/helpers/dot_helper.rb

@@ -8,9 +8,15 @@ module DotHelper
8 8
         } rescue false)
9 9
       decorate_svg(svg, agents).html_safe
10 10
     else
11
-      tag('img', src: URI('https://chart.googleapis.com/chart').tap { |uri|
12
-            uri.query = URI.encode_www_form(cht: 'gv', chl: agents_dot(agents))
13
-          })
11
+	uriquery=URI.encode_www_form(cht: 'gv', chl: agents_dot(agents))
12
+	#Get query maximum length should be under 2048 bytes with including "chart?" of google chart request url
13
+	if uriquery.length > 2042
14
+		"Too many agent to display, please check unused agents"
15
+	else
16
+	      tag('img', src: URI('https://chart.googleapis.com/chart').tap { |uri|
17
+        	    uri.query = uriquery
18
+	          })
19
+	end
14 20
     end
15 21
   end
16 22