Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] XPath namespace errors from atom feed #5187

Closed
se35710 opened this issue Oct 14, 2022 · 6 comments · Fixed by #5247
Closed

[Bug] XPath namespace errors from atom feed #5187

se35710 opened this issue Oct 14, 2022 · 6 comments · Fixed by #5247
Labels

Comments

@se35710
Copy link
Contributor

se35710 commented Oct 14, 2022

Bug Report

Current Behavior

When using XPath with a Github release atom feed, Scoop throws the following error:

MethodInvocationException: D:\Dev\Projects\scoop\bin\checkver.ps1:313
Line |
 313 |                  $nsmgr.AddNamespace($_.LocalName, $_.Value)
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "AddNamespace" with "2" argument(s): "Prefix "xmlns" is reserved for use by XML."

$nsmgr.AddNamespace($_.LocalName, $_.Value)

Expected Behavior

Scoop should happily import all namespaces

Additional context/output

N/A

Possible Solution

            $nsList | ForEach-Object {
                if ($_.LocalName -eq "xmlns") {
                    $nsmgr.AddNamespace("ns", $_.Value)
                }
            }

Not sure if this is a good idea, but we need a predictable namespace name for XPath ease of use.

System details

Windows version: [e.g. 7, 8, 10, 11]
11

OS architecture: [e.g. 32bit, 64bit, arm64]
64bit

PowerShell version: [output of "$($PSVersionTable.PSVersion)"]
Tested on 5.1 and 7.2.6

Additional software: [(optional) e.g. ConEmu, Git]
N/A

Scoop Configuration

N/A

@se35710 se35710 added the bug label Oct 14, 2022
@niheaven
Copy link
Member

I'm not using XPath and could you provide some test cases?

@se35710
Copy link
Contributor Author

se35710 commented Oct 14, 2022

Here is an example that works, but not a real use-case.

It's using the ns namespace from my comment above.

{
    "description": "The IBM Semeru Runtimes are free production-ready binaries built with the OpenJDK class libraries and the Eclipse OpenJ9 JVM",
    "homepage": "https://developer.ibm.com/languages/java/semeru-runtimes/",
    "version": "18.0.2-9-0.33.1",
    "license": "GPL-2.0-only WITH Classpath-exception-2.0,EPL-2.0",
    "architecture": {
        "64bit": {
            "url": "https://github.com/ibmruntimes/semeru18-binaries/releases/download/jdk-18.0.2+9_openj9-0.33.1/ibm-semeru-open-jdk_x64_windows_18.0.2_9_openj9-0.33.1.zip",
            "hash": "cba270f40308ac503a039bb9f53becc0da679e550b019ed6721634229b1e65f8"
        }
    },
    "extract_dir": "jdk-18.0.2+9",
    "env_add_path": "bin",
    "env_set": {
        "JAVA_HOME": "$dir"
    },
    "checkver": {
        "url": "https://github.com/ibmruntimes/semeru18-binaries/releases.atom",
        "xpath": "/ns:feed/ns:entry[1]/ns:title",
        "regex": "(?<tag>jdk-(?<major>(?<jdk>[\\d]+)[\\d.]+)(?:\\%2B|\\+)(?<build>[\\d]+)(?<patch>[\\d.]*)(?:(?<oj>_openj9?)(?<jvmver>-[\\d.]+(?:-m[\\d]+)?))?)",
        "replace": "${major}-${build}${patch}${jvmver}"
    },
    "autoupdate": {
        "architecture": {
            "64bit": {
                "url": "https://github.com/ibmruntimes/semeru18-binaries/releases/download/$matchTag/ibm-semeru-open-jdk_x64_windows_$matchMajor_$matchBuild$matchPatch_openj9$matchJvmver.zip"
            }
        },
        "hash": {
            "url": "$url.sha256.txt",
            "regex": "^([a-fA-F0-9]+)\\s"
        },
        "extract_dir": "jdk-$matchMajor+$matchBuild"
    }
}

@niheaven
Copy link
Member

            $nsList | ForEach-Object {
                if ($_.LocalName -eq 'xmlns') {
                    $nsmgr.AddNamespace('ns', $_.Value)
                    $xpath = $xpath -replace '/([^:/]+)((?=/)|(?=$))', '/ns:$1'
                } else {
                    $nsmgr.AddNamespace($_.LocalName, $_.Value)
                }
            }

It works. I'll submit a PR and please test it.

@se35710
Copy link
Contributor Author

se35710 commented Oct 15, 2022

Tested, and working great!

@adthom
Copy link

adthom commented Sep 10, 2023

This bug was only fixed in the checkver.ps1 -- the issue persists in the autoupdate.ps1 xpath implementation in the find_hash_in_xml function. The same fix works in my local testing.

@rashil2000
Copy link
Member

Hi, could you raise a PR for the same?
Thanks!

adthom added a commit to adthom/Scoop that referenced this issue Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants