Skip to content

Handle inline regex modifiers and invalid schema patterns in hover#1244

Merged
datho7561 merged 2 commits intoredhat-developer:mainfrom
shin19991207:fix-874
May 1, 2026
Merged

Handle inline regex modifiers and invalid schema patterns in hover#1244
datho7561 merged 2 commits intoredhat-developer:mainfrom
shin19991207:fix-874

Conversation

@shin19991207
Copy link
Copy Markdown
Member

What does this PR do?

  • Support inline schema pattern modifiers: (?s), (?m), (?i), and their combined forms such as (?ms) / (?sm). Note that these modifiers are not part of the "portable JSON Schema regex guidance" documented at https://json-schema.org/understanding-json-schema/reference/regular_expressions, but I think supporting them is useful for schemas.
  • Show diagnostic Invalid pattern: "..." when a schema uses unsupported regex syntax
  • Before this fix, validation and hover failed with error Request textDocument/hover failed with message: Invalid regular expression: .... Both validation and hover should now continue to work even when schemas contain inline modifiers or unsupported patterns.

What issues does this PR fix or reference?

Fixes #874

Is it tested? How?

  • New automated tests
  • Tested manually

test-pattern-schema.json:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "caseInsensitiveField": {
      "type": "string",
      "description": "Field with case-insensitive pattern.",
      "pattern": "(?i)^(yes|no)$"
    },
    "multilineOnly": {
      "type": "string",
      "description": "Field with multiline pattern.",
      "pattern": "(?m)^start.*end$"
    },
    "dotallOnly": {
      "type": "string",
      "description": "Field with dotall pattern.",
      "pattern": "(?s)^start.*end$"
    },
    "multilineAndDotallCombinedFlags": {
      "type": "string",
      "description": "Field with multiline and dotall pattern.",
      "pattern": "(?ms)^start.*end$"
    },
    "dotallAndCaseInsensitiveFieldFlags": {
      "type": "string",
      "description": "Field with dotall and case-insensitive pattern.",
      "pattern": "(?s)(?i)test.*content"
    },
    "allFlags": {
      "type": "string",
      "description": "Field with case-insensitive, multiline, and dotall pattern.",
      "pattern": "(?ims)^START.*END$"
    },
    "unsupportedPattern": {
      "type": "string",
      "description": "Field with unsupported pattern.",
      "pattern": "(?x)text .*"
    }
  }
}
# yaml-language-server: $schema=./test-pattern-schema.json
caseInsensitiveField: YES

multilineOnly: |-
  ignored line
  start middle content end
  another ignored line

dotallOnly: |-
  start
  middle content
  end

multilineAndDotallCombinedFlags: |-
  ignored line
  start
  middle content
  end
  another ignored line

dotallAndCaseInsensitiveFieldFlags: |-
  TEST
  middle content
  CONTENT

allFlags: |-
  ignored line
  start
  middle content
  end
  another ignored line

unsupportedPattern: text content

…hover

Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Signed-off-by: Morgan Chang <shin19991207@gmail.com>
@shin19991207 shin19991207 requested a review from datho7561 as a code owner May 1, 2026 17:03
Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me.

Side node: kind of silly that ajv doesn't report if the regex is invalid when validating the schema.

@datho7561 datho7561 merged commit d2eedcc into redhat-developer:main May 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request textDocument/hover failed with message: Invalid regular expression: /(?s).*/: Invalid group

2 participants