lhs icon indicating copy to clipboard operation
lhs copied to clipboard

Conversion failure when a text field start with a date or datetime

Open fernandomm opened this issue 2 years ago • 0 comments

When LHS is used to access a text attribute that starts with a date or datetime, it converts the initial date ignoring everything else.

Sample json:

[
  {
    "id": 1,
    "text": "2021-10-28 Sample message."
  }
]

Accessing text attribute returns a date and not an string:

[1] > ticket = Ticket.where(id: 1)
=> Ticket 47342870532040
{:id=>1, :text=>"2021-10-28 Sample message."}
[2] > ticket.first.text
=> Thu, 28 Oct 2021

The issue seems to be caused by the regex in:

https://github.com/local-ch/lhs/blob/c6f7c6291d130fde264e26edabf059a499f93b8f/lib/lhs/concerns/proxy/accessors.rb#L125

Limiting it with \A and \z seems to fix the problem without any side effects:

def date_time_regex
  /\A(?<date>\d{4}-\d{2}-\d{2})?(?<time>T\d{2}:\d{2}(:\d{2}(\.\d*.\d{2}:\d{2})*)?)?\z/
end

fernandomm avatar Oct 28 '21 19:10 fernandomm