Skip to content

[cs] Misleading conditional #216

Open
@sfgeorge

Description

@sfgeorge

The following conditional found in lib/punchblock/component/output.rb has a misleading final elsif:

def xml_value
  if ssml?
    value.to_s
  elsif urilist?
    value.to_s
  elsif
    value
  end
end

One may think that the above elsif is equivalent to ... else value end or ... elsif value; value end, but neither is the case. As seen in this gist, it's a strange, empty elsif block with nil as a return value. The method is functionally equivalent to the following:

def xml_value
  if ssml?
    value.to_s
  elsif urilist?
    value.to_s
  elsif value
    nil
  end
end

Additionally, if we change that nil to ">FOO!" the test suite continues to pass. So while this is a private method, we should probably fix this and ensure it is tested.

What is the desired outcome of this case? value, value.to_s, or KABOOM! with a raised exception?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions