Note on how to escape file path in bufname argument:
let bufnr_val = bufnr('^'..escape(full_or_partial_path, '\.*?~,^${}[]')..'$')
Note that this still match either full or partial path. If you want to match full path only do this
if bufnr_val >= 0 && expand('#'..bufnr_val..':p') != full_path
let bufnr_val = -1
endif
This is because the documentation contains the following:
bufnr([{buf} [, {create}]]) *bufnr()*
The result is the number of a buffer, as it is displayed by
the `:ls` command. For the use of {buf}, see |bufname()|
above.
bufname([{buf}]) *bufname()*
The result is the name of a buffer. Mostly as it is displayed
by the `:ls` command, but not using special names such as
"[No Name]".
If {buf} is omitted the current buffer is used.
If {buf} is a Number, that buffer number's name is given.
Number zero is the alternate buffer for the current window.
If {buf} is a String, it is used as a |file-pattern| to match
with the buffer names. This is always done like 'magic' is
set and 'cpoptions' is empty. When there is more than one
match an empty string is returned.
A full match is preferred, otherwise a match at the start, end
or middle of the buffer name is accepted. If you only want a
full match then put "^" at the start and "$" at the end of the
pattern.
*file-pattern*
The pattern is interpreted like mostly used in file names:
* matches any sequence of characters; Unusual: includes path
separators
? matches any single character
\? matches a '?'
. matches a '.'
~ matches a '~'
, separates patterns
\, matches a ','
{ } like \( \) in a |pattern|
, inside { }: like \| in a |pattern|
\} literal }
\{ literal {
\\\{n,m\} like \{n,m} in a |pattern|
\ special meaning like in a |pattern|
[ch] matches 'c' or 'h'
[^ch] match any character but 'c' and 'h'
Note that for all systems the '/' character is used for path separator (even
for MS-Windows). This was done because the backslash is difficult to use in a
pattern and to make the autocommands portable across different systems.