Skip to content

In API to create new wiki, sending ampersand in name field results in '&' #9856

Open
@krcrouse

Description

@krcrouse

I believe this is a bug in how the API is processing the strings in the request body for wiki creation - but this doesn't appear when using the manual online interface.

Through the online interface, there is no issue creating a new wiki page with an ampersand. Pressing the new button and typing A & B creates a wiki that appears as A & B in the wiki panel and that has a link of https://osf.io/{node_id}/wiki/A%20%26%20B/

The processor that handles API requests, on the other hand, is not handling this correctly for the name field, at least when using the native requests library with python:

  • If you pass in the unescaped "A & B" in the request body, the name in the Wiki Panel appears as A & B; however, the formatted title appears correct when reading the page, presumably because the website is rendering the &
  • If you attempt to escape it by passing in "A %26 B" or "A%20%26%20B" or "A+%26+B", these are all fully escaped and appear as listed.

Trivial example that leads to the described behavior.

import requests 

resp = requests.post(
    f'https://api.osf.io/v2/nodes/{node_id}/wikis/', 
    headers={"Authorization" : "Bearer " + access_token},
    data={
        'type': 'wikis',
        'content': "#Heading\n\nText text text",
        'name': "A & B",
    }) 

print(resp.json())

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions