Module: RightDevelop::CI::Util

Defined in:
lib/right_develop/ci/util.rb

Constant Summary collapse

JAVA_CLASS_NAME =

Regular expression used to determine which characters of a string are allowed in Java class names.

/[A-Za-z0-9_]/
JAVA_PACKAGE_SEPARATOR =

The dot character gets special treatment: even if we XML-escape it, Jenkins will assume that it functions as a package separator. So, we’ll replace it with an equivalent Unicode character. Hooray homographic character attacks!

'.'
JAVE_PACKAGE_SEPARATOR_HOMOGLYPH =

Replacement codepoint that looks a bit like a period

'·'

Class Method Summary collapse

Class Method Details

.pseudo_java_class_name(name) ⇒ String

Make a string suitable for parsing by Jenkins JUnit display plugin by escaping any non-valid Java class name characters as an XML entity. This prevents Jenkins from interpreting “hi1.2” as a package-and-class name.

Parameters:

  • name (String)

Returns:

  • (String)

    string with all non-alphanumerics replaced with an equivalent XML hex entity



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/right_develop/ci/util.rb', line 23

def pseudo_java_class_name(name)
  result = ''

  name.each_char do |chr|
    if chr =~ JAVA_CLASS_NAME
      result << chr
    elsif chr == JAVA_PACKAGE_SEPARATOR
      result << JAVE_PACKAGE_SEPARATOR_HOMOGLYPH
    else
      chr = chr.unpack('U')[0].to_s(16)
      result << "&#x#{chr};"
    end
  end

  result
end