Bug: Keyboard Maestro does not accept '%252C' escape codes

Using the latest KM on MacOS Monterey, I have a URL which works fine if I type it into Safari or execute it from the command line, like this:

open obsidian://advanced-uri?vault=wealthyvault&filepath=Knowledge%252FArt%252C%2520Spirituality%252C%2520Psychology%252FEmotional%2520Journal.md

However, in KM, I get this message:


2022-07-14.13.33.26.CleanShot.Safari

Here is the code for the macro:

It's very strange because this macro, very similar, works fine every time:

with: Default Application vs with: Obsidian ?

Perhaps you just need to change that switch at bottom left ?

1 Like

I tried that. I think the problem is down to the existence of the %252C code in the URL. It is valid but KM seems to disallow it and the "Open URL" label turns yellow when I type it in. As soon as I delete the %252C bit, the string turns green. This should not happen in my view as it is clearly legal syntax.

In fact, if I change the %252C to literal comma , characters, then it works fine, but I think this is a bug in KM.

I'm not so sure -- an URL-encoded , is %2C. And you encode %2C again to get %252C.

It looks like you are double-encoding somehow and while Safari/Terminal can make sense of it, KM (for whatever reason) can't.

What's the actual, plain text, string you are trying to pass to the filepath parameter? Try passing that through KM's "Percent Encode URL" filter, then using the result in your KM action.

1 Like

Oh, yes, you are right, I thought that %252C meant comma because when I deleted it and replaced it with a comma, it opened the correct file, much to my surprise. So %25 must be some sort of required escape code used by the program generating the string, Obsidian.md (http://obsidian.md)
The string includes a command which will be parsed by Obsidian, so I'd like to just not mess with it. I'm just copy/pasting a URL from Obsidian that works from the command line.
I would like to know why is KM in the business of policing URLs? I don't want this gatekeeping, it's in my way, not helping at the moment. :slight_smile: Is there some way to make it not do this sometimes? :smiley:

No -- %25 is how you include an actual % in a URL without it become the "escape indicator". If you want, for example, "=Planning,Footpaths" in a URL then it would be =Planning%2CFootpaths.

All the URLs you've shown above exhibit the same pattern -- the character you want to encode has been encoded, and then you've encoded the % symbol of the encoded character. A space is %20, but you've got %2520, etc. This is not how Obsidian wants things done, it want %25, %20, and so on, and I'm more surprised that Safari/Terminal have made sense of what you are asking than that KM can't!

1 Like

Interesting, so I'm actually coming back to the basic question of why is KM even complaining? I mean I know it's got %252F in it, but is that illegal? No, it's not, because as you point out, it evaluates to %2F. Which will then be parsed again later internally apparently. What technically is KM noticing in the string that is triggering it to complain? Thanks for your patience while I try to figure this out.

I have opened a ticket with the Obsidian-URI developer I'll update this thread with whatever I learn probably. :slight_smile:

It isn't.

(It's reporting an invalid URL response from Obsidian).

As @Nige_S pointed out – "This is not how Obsidian wants things done"


You can FWIW, test whether the macOS Foundation libraries will be able to work with a given string as a valid URL (compliant with the RFC 2396 standard).

If you pass a string argument to NSURL.URLWithString, it will return a Nil value if the string can't be parsed as a well-formed URL.

JavaScript for Automation:

$.NSURL.URLWithString(
    "insert url between these quotes"
).isNil() ? (
    "Doesn't conform to RFC 2396"
) : "Accepted as a URL"

See: URLWithString: | Apple Developer Documentation

1 Like

I don't know enough about the URL spec to know if it's illegal or not (and if you did I suspect this thread would never have been started :wink: ).

What I know is that you are asking KM to send %252F to the server. The server than decodes it to %2F. The server then doesn't know what to do because %2F is not the literal / it was expecting.

I haven't tested, but it looks like Safari/Terminal are taking your URL, deciding it is malformed, doing their best to interpret it, decoding %252F to %2F then sending that to the server -- which IMO is at least "undocumented behaviour" if not an outright bug. What if I wanted to send the "double-encoded" version so the server could then pass on the "single-encoded" version to another process without having to re-encode the string (admittedly bad practice, but I've seen it done!)?

Best bet is to do things "properly" in the first place -- congrats for raising the bug with the developer, it'll be interesting to see what they say.

1 Like

OK as you rightly point out, I'm not an expert on URL codes and how Obsidian parses them. However, I can definitely state that %252F is not illegal. Proof: I created a file called. %2F.html and put it on my server, and used the allegedly "illegal" URL syntax to load the file properly at https://wealthychef.net/%252F.html. This works in Chrome and Safari. It also works on Chrome in Windows 11, so it's not a MacOS thing. From where I'm sitting this is valid URL syntax using a valid escape sequence.

Why do you say it's reporting an invalid URL response from Obsidian? I don't think this is correct, because as soon as I type this supposedly "invalid" URL into KM the field label turns yellow. It has not done anything, not communicated with Obsidian at this point, I've just entered a string into it's URL field.

Also, can your theory explain why this URL works fine in Keyboard Maestro? I just replaced the %252C sequences with commas, but I left the %2520 and %252F sequences in place. obsidian://advanced-uri?vault=wealthyvault&filepath=Knowledge%252FArt,%2520Spirituality,%2520Psychology%252FEmotional%2520Journal.md&mode=append
Works like a charm this way.... So I think my subject line is still valid for this thread. Am I wrong?

I think you misunderstand what's going on in your various browsers (which are working around the illegal encoding Obsidian is contriving).

Here's a simple reference to URL Encoding, which states unequivocally:

URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.

Just two hex digits. never three. That Obsidian gives you four hex digits (alphanumeric) is an obvious error. I'm guessing it is trying to encode the percent sign (which it should not) as %25. And the 2F is an underscore. Here's the reference for those codes:

HTML URL-Encoding Reference

(You might need to encode the percent sign if there was a literal percent sign in the url, like "%100 Guaranteed" but that doesn't seem to be what's going on here. In fact, all the spaces in your URL -- which should encode simply as %20 -- are encoded %2520 which seems like an attempt to encode the percent sign as a literal even when used as a delimiter. Clearly an error.).

So not a Keyboard Maestro bug.

I just have to go back to the example I provided where %252F is parsed correctly as %2F. I think we are just talking past each other. I agree that %252F is not the proper encoding for %_ which seems to be your complaint, am I right? However, we agree that in fact it is the proper encoding for %2F. So it's legal syntax and there is nothing for KM to detect or reject in my view. How does KM know that I'm not referring correctly to a URL with several '%' signs in it? I claim it doesn't and shouldn't be trying to figure any of that out as I've shown there are valid use cases for such URLs. I do not know what technical reasons there might be within KM's code, but "it's not a valid URL" is just not accurate.

Yes, it %252F correctly parsed (actually unencoded) to %2F. But you don't want that. You want a literal /, which requires unencoding %252F to %2F and then unencoding that to /.

Your example works because you have created a file named %2F.html -- it would work exactly the same if you had called it %ThisIsMyFile.html and gone to the URL wealthychef.net/%25ThisIsMyFile.html. You are only encoding the % character, nothing more.

The (IMO lax) parsing of your URL by the various browsers really isn't worth arguing about -- for all we know they are trying the first, single-unecoded, URL, getting an "URL not found" response, then trying again with the doubly-unencoded version just in case.

What we do know is that Obsidian expects you to encode a literal / as %2F -- that's explicitly stated on the Obsidian website. So save yourself some pain and do it "properly", even when the utility generating the string for you is doing it wrong.

No.

You would never encode the percent delimiter for a hex sequence. Never. You would encode it for a literal percent sign so it wouldn't be taken for a delimiter.

But you don't get to double dip (decode twice).

Yes, %252F decodes as "%2F" literally, but there is no further decoding of that literal. The correct encoding would be %2F period. Just as the correct encoding of "%2F20" is simply %20 for a space, which is probably a clearer example. You'll never get a space decoding an encoding of "%2F20" -- it's simply malformed.

Kudos to Keyboard Maestro for pointing out the problem. As a programming environment it has an obligation to blow the whistle on errors like this before they become larger problems that are more difficult to trace.

%252F decodes as "%2F" literally , but there is no further decoding of that literal

Ah now we are getting somewhere. So it's a valid string.
It is not up to KM to decide how much further decoding gets done down the line. Obsidian clearly does decode the string further after it is passed to it, as it correctly opens the right note for me.

You'll never get a space decoding an encoding of "%2F20" -- it's simply malformed.

Unless it is twice encoded, which if it is, it's done perfectly. Why does KM try to decide this undecidable question? My point continues to be that this is not necessarily a problem. Obsidian is free to double, triple or quadruple encode URLs and use them internally for its own purposes, agreed? Anyhow, you and I are just arguing about opinions now. I am clear that this is a valid URL, and you think it's not, fine. I think I will wait for either the developer of KM (if he monitors this space) or the developer of the plugin to respond about the technical facts. Thanks for helping me understand the problem.

Another counter-evidence to this claim is that this command directly opens the URI with Obsidian from the command line. Safari is not involved here. So for sure, Obsidian wants this format for whatever reason, I think because it double-encodes the URIs.

rcook@MacBook-Pro-2021 (~ ): open -a Obsidian "obsidian://advanced-uri?vault=wealthyvault&filepath=Knowledge%252FArt%252C%2520Spirituality%252C%2520Psychology%252FEmotional%2520Journal.md"

It works perfectly. QED

1 Like

I have confirmed with the developer that this is not an error and is the desired format for this URI.

No. That's not what standards are about. If they'd like to do their own encoding, they can use something else entirely to avoid confusion rather than usurp the conventional delimiter.

I'm simply elucidating a well-documented standard not an opinion. Obsidian may think itself clever (I see from your subsequent post it has confirmed its approach), but I think it is very poor practice to practice subterfuge on standards.