question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore trailing slash from path field

See original GitHub issue

Hi!

First, thank you for your awesome tool 😉 Since a few weeks I have a trouble creating comments on my blog, Staticman creates a branch on my repository, but doesn’t create a commit, and when submitting a new comment I have this page:

{

  "code": 422,

  "status": "Unprocessable Entity",

  "message": "{\"message\":\"path contains a malformed path component\",\"errors\":[{\"resource\":\"Commit\",\"field\":\"path\",\"code\":\"invalid\"}],\"documentation_url\":\"https://developer.github.com/v3/repos/contents/\"}"

}

Here is my staticman.yml:

comments:
  path: "_data/comments/"
  allowedFields: ["name", "email", "url", "message", "post_id"]
  allowedOrigins: ["ilphrin.com", "localhost"]
  branch: "master"
  filename: "{fields.name}_{@timestamp}"
  format: "yml"
  generatedFields:
    date:
      type: date
      options:
        format: "timestamp-seconds"
  moderation: true
  name: "ilphrin.com"
  requiredFields: ["name", "email", "message", "post_id"]
  commitMessage: "New comment on the blog"

And here is my form for submitting a comment (I am using Jekyll):

  <form class="ui form" method="POST" action="https://api.staticman.net/v2/entry/Ilphrin/ilphrin.com/master/comments">
    <input name="options[slug]" type="hidden" value="{{ page.slug }}">
    <input name="options[redirect]" type="hidden" value="https://ilphrin.com{{page.url}}">
    <input name="options[origin]" type="hidden" value="https://ilphrin.com" />
    <input type="hidden" name="fields[post_id]" value="{{page.id}}" />
    <div class="ui inverted segment">
      <h2 class="ui dividing header">Commenter</h2>
      <div class="field">
        <div class="three fields">
          <div class="field">
            <label>Nom</label>
            <input name="fields[name]" placeholder="Requis" type="text" required/>
          </div>
          <div class="field">
            <label>Email</label>
            <input name="fields[email]" placeholder="Requis, non publié" type="email" required/>
          </div>
          <div class="field">
            <label>Lien</label>
            <input name="fields[url]" placeholder="Optionnel" type="text"/>
          </div>
        </div>
      </div>
      <div class="field">
        <label>Allez-y parlez ;)</label>
        <textarea name="fields[message]" placeholder="Requis" required></textarea>
      </div>
      <button class="ui submit button" type="submit" name="submit">Envoyer</button>
    </div>
  </form>

And I couldn’t figure out how to fix this issue 😕

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
zburgermeisztercommented, Feb 25, 2017

This happens to me when the options[slug] field is missing from the comment form. So it might be empty in your case @Ilphrin

It’s because staticman is trying to write to _data/{slug}/entry{timestamp}.yml, and github API falls over on the double slashes.

It may help you @eduardoboucas

0reactions
eduardoboucascommented, Feb 26, 2017

I think the solution here is quite simple: we just need to remove a trailing slash from the path field, if there is any.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the simplest way to remove a trailing slash from each ...
The accepted answer will trim ONE trailing slash. One way to trim multiple trailing slashes is like this:
Read more >
Don't allow adding source paths with trailing slashes ... - Drupal
I observed when I created a redirect and the source path ends with slash the redirect doesn't work. Example: source: test/this/
Read more >
Should You Have a Trailing Slash at the End of URLs? - Ahrefs
The trailing slash is generally used to distinguish a directory which has the trailing slash from a file that does not have the...
Read more >
How to Remove a Trailing Slash from a String in JavaScript
Use the String.replace() method to remove a trailing slash from a string, e.g. str.replace(/\/+$/, '') . The replace method will remove the trailing...
Read more >
Excel formula: Remove trailing slash from url - Got It AI
We can remove a trailing slash from a URL LINK by using a combination of LEFT, RIGHT, and LEN functions. This will delete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found