diff --git a/demo-output.yaml b/demo-output.yaml index 052fc04a..47912ede 100644 --- a/demo-output.yaml +++ b/demo-output.yaml @@ -767,6 +767,19 @@ data: dependency innerText: "\n junit\n junit\n 4.11\n test\n " matchingXML: junitjunit4.11test + xml-test-key-match: + description: Test code snippets when match is a key of a XML node + category: potential + incidents: + - uri: file:///analyzer-lsp/examples/java/beans.xml + message: The code snippet should point to in the beans.xml file + codeSnip: " 8 *\n 9 * http://www.apache.org/licenses/LICENSE-2.0\n10 *\n11 * Unless required by applicable law or agreed to in writing, software\n12 * distributed under the License is distributed on an \"AS IS\" BASIS,\n13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n14 * See the License for the specific language governing permissions and\n15 * limitations under the License.\n16 -->\n17 \n22 \n" + lineNumber: 17 + variables: + data: beans + innerText: |2+ + + matchingXML: "" errors: error-rule-001: |- unable to get query info: yaml: unmarshal errors: diff --git a/examples/java/beans.xml b/examples/java/beans.xml new file mode 100644 index 00000000..94b96809 --- /dev/null +++ b/examples/java/beans.xml @@ -0,0 +1,22 @@ + + + + \ No newline at end of file diff --git a/provider/internal/builtin/service_client.go b/provider/internal/builtin/service_client.go index 0e568f26..64eeaa65 100644 --- a/provider/internal/builtin/service_client.go +++ b/provider/internal/builtin/service_client.go @@ -173,7 +173,11 @@ func (p *builtinServiceClient) Evaluate(ctx context.Context, cap string, conditi "data": node.Data, }, } - location, err := p.getLocation(ctx, ab, node.InnerText()) + content := strings.TrimSpace(node.InnerText()) + if content == "" { + content = node.Data + } + location, err := p.getLocation(ctx, ab, content) if err == nil { incident.CodeLocation = &location lineNo := int(location.StartPosition.Line) diff --git a/rule-example.yaml b/rule-example.yaml index 6bc08787..45980317 100644 --- a/rule-example.yaml +++ b/rule-example.yaml @@ -231,3 +231,14 @@ deprecatedIn: "v1.9.0" removedIn: "v1.16.0" replacementAPI: "apps/v1" +- category: potential + description: "Test code snippets when match is a key of a XML node" + message: "The code snippet should point to in the beans.xml file" + ruleID: xml-test-key-match + when: + builtin.xml: + filepaths: + - beans.xml + namespaces: + b: http://xmlns.jcp.org/xml/ns/javaee + xpath: /b:beans \ No newline at end of file