module JSI
module Schema::Validation::Pattern
def internal_validate_pattern(result_builder)
if keyword?('pattern')
value = schema_content['pattern']
if value.respond_to?(:to_str)
if result_builder.instance.respond_to?(:to_str)
begin
regexp = Regexp.new(value)
result_builder.validate(
regexp.match(result_builder.instance),
'instance string does not match `pattern` regular expression value',
keyword: 'pattern',
)
rescue RegexpError => e
result_builder.schema_error(-"`pattern` is not a valid regular expression: #{e.message}", 'pattern')
end
end
else
result_builder.schema_error('`pattern` is not a string', 'pattern')
end
end
end
end
end