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

Convert array to string before cleaning up value. (#184) #185

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

hktang
Copy link

@hktang hktang commented Feb 6, 2024

This is a quick fix assuming the supplied value is an array of strings.
I had to apply this patch for my application to work.
Please kindly review. Suggestions much appreciated!

Ref: #184

Copy link
Owner

@seboettg seboettg left a comment

Choose a reason for hiding this comment

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

please consider my comment.

src/Rendering/Text.php Outdated Show resolved Hide resolved
@hktang
Copy link
Author

hktang commented May 28, 2024

@seboettg Thanks again for your reply. Having a closer look, it seems the problematic item is "Copyright", which is an array containing one (or potentially more) objects, as indicated below.

I wonder whether we can look at the upstream and check how this complex array/object ends up here inside htmlspecialchars? I am sorry I am not familiar with the codebase at the moment. If you could point me where to look I am happy to help.

At the moment, I added a test case, and hardcoded a fix specific for the license field, i.e. just extracting the URL from the license. I don't think it's an ideal fix at all, and your feedback would be appreciated. Maybe, we could even ignore the license field as Bibtex does not enforce it.

 "license": [
            {
                "URL": "https://creativecommons.org/licenses/by/4.0/",
                "content-version": "vor",
                "delay-in-days": 0,
                "start": {
                    "date-parts": [
                        [
                            2023,
                            11,
                            8
                        ]
                    ],
                    "date-time": "2023-11-08T00:00:00Z",
                    "timestamp": 1699401600000
                }
            }
        ],

@hktang
Copy link
Author

hktang commented May 29, 2024

Perhaps, it's worth checking for a license field like below, inside the render() function, and add the string extraction logic to a new function renderLicense()? The thing is, License is not defined in the CSL data schema.

elseif ($this->toRenderTypeValue === "license") {
    $renderedText = $this->renderLicense($data->{$this->toRenderTypeValue});
    break;
}

After implementing the above, I found the ISSN field in this example is still causing complaints, as it is an array containing a string, like ["2071-1050"], breaking htmlspecialchars() again. Having checked the CSL data schema, it seems ISSN/ISBN must be a string. So, this is getting interesting.

For your reference, the JSON is retrieved from DOI content negotiation. I wonder why it returns data in non-compliant format...

curl -LH "Accept: application/vnd.citationstyles.csl+json, application/rdf+xml" https://doi.org/10.3390/su152215733

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.

None yet

4 participants