nio2: detect '..' and suchlike elements - nio2

I wish to use a string handed to me as a parameter as an element of a pathname. I do not wish to be troubled with 'Little Bobby Tables'. That is, I don't want '..' to be acceptable. I want this to work with an arbitrary NIO2 FileSystem, so just looking for the string .. isn't good enough. I can make some checks, such as !path.isAbsolute(), and path.getNameCount() == 1 to filter out other problem cases, but can I do anything other than pass it to resolve and look for the wrong name count to tell if it has the semantics of ..?

toRealPath()
Is mostly the answer. The method on a path after resolved gives you
the real path after resolving parent (e.g. "..") and links.
You can then use root.startsWith( path ) to quickly check that it is in your subtree.
But: Works only for existing files.

Related

How to filter by tag in Jaeger

When trying to filter by tag, there is a small popup:
I have been looking for logfmt around, but all I can find is key=value format.
My questions are:
Is there a way for something more sophisticated? (starts_with, not equal, contains, etc)
I am trying to filter by url using http.url="http://example.com?bla=bla&foo=bar". I am pretty sure the value exists because I am copy/pasting from my trace. I am getting no results. Do I need to escape characters or do something else for this to work?
I did some research around logfmt as well. Based on the documentation of the original implementation and in the Python implementation of the parser (and respective tests), I would say that it doesn't support anything more sophisticated (like starts_with, not equal, contains). And this is because the output of the parser is a simple dictionary (with no regex involved in the values).
As for the second question, using the same mentioned Python parser, I was able to double-check that your filter looks fine:
from logfmt import parse_line
parse_line('http.url="http://example.com?bla=bla&foo=bar"')
Output:
{'http.url': 'http://example.com?bla=bla&foo=bar'}
This makes me suspect of an issue on the Jaeger side, but this is as far as I could go.

Add path segment at last part of URL with ZnUrl

I am using Pharo 3 and I want to add a path segment as the last part of an URL for example http://example.com/myapp?key1=param1&key2=param2 and I want to get /myParam added to the last part. With ZnUrl I tried with #addSegment:
(ZnUrl fromString: 'http://example.com/myapp?key1=param1&key2=param2')
addPathSegment: 'myParam'
but results in
http://example.com/myapp/myParam?key1=param1&key2=param2
How could I configure the ZnUrl to get?
http://example.com/myapp?key1=param1&key2=param2/myParam
The thing you are describing is not a valid URL:
So what you are talking about is not an addition of a path segment, but rather string concatenation.
You can consider doing:
ZnUrl fromString: 'http://example.com/myapp?key1=param1&key2=param2/myParam'
or if you get a url from somewhere else,
(self asString, '/myParam') asUrl
should work too.
You can also do more magic to get everything to work, but in a first place you have to redesign your URL structure, to fit the standards (if you can influence it)

SWI prolog make set of variables name with rbtrees or others means

I have got a term from which I want to get set of variables name.
Eg. input: my_m(aa,b,B,C,max(D,C),D)
output: [B,C,D] (no need to be ordered as order of appearance in input)
(That would call like set_variable_name(Input,Output).)
I can simply get [B,C,D,C,D] from the input, but don't know how to implement set (only one appearance in output). I've tried something like storing in rbtrees but that failed, because of
only_one([],T,T) :- !.
only_one([X|XS],B,C) :- rb_in(X,X,B), !, only_one(XS,B,C).
only_one([X|XS],B,C) :- rb_insert(B,X,X,U), only_one(XS,U,C).
it returns tree with only one node and unification like B=C, C=D.... I think I get it why - because of unification of X while questioning rb_in(..).
So, how to store only once that name of variable? Or is that fundamentally wrong idea because we are using logic programming? If you want to know why I need this, it's because we are asked to implement A* algorithm in Prolog and this is one part of making search space.
You can use sort/2, which also removes duplicates.

Possible to apache mod_autoindex and mod_dir to return directory listing via AJAX?

This probably sounds silly, after all I could generate the file listing via PHP, right?
But I am becoming more and more fascinated with what all can be accomplished with just Apache and JQuery alone. I've been reading documentation and it seems like things are SO VERY close, but I am obviously missing a few things.
First, can I set a directory listing to a "path" or file name,
overwriting the default, "index.html"? In particular, I am trying to
configure any request ending in "ndx.mnu" to return the directory
listing:
"DirectoryIndex ndx.mnu"
...does not accomplish that. Anyideas?
Second, does anyone know of a way to impose a numerical sort similar
to the way in which VersionSort works for files? Right now:
"foo-1, foo-2"
sorts correctly but what if I want to force:
"foo-1, bar-2"
to be order returned?
Trying to make something with as few moving parts as possible. Any pointers to read up would be appreciated.
Well for the second part, you want to sort by the number rather than the letters correct? You should be able to read the string backwards and sort from end to beginning. Using strrev() to reverse it, you can write a sorting algorithm to do that.
Or if all the file use the '-#' notation then $num = explode('-', $string); and sort by $num[1] (which should be the number on the end) though if some file names contain multiple '-' you could use regular expressions.

TSearch2 - dots explosion

Following conversion
SELECT to_tsvector('english', 'Google.com');
returns this:
'google.com':1
Why does TSearch2 engine didn't return something like this?
'google':2, 'com':1
Or how can i make the engine to return the exploded string as i wrote above?
I just need "Google.com" to be foundable by "google".
Unfortunately, there is no quick and easy solution.
Denis is correct in that the parser is recognizing it as a hostname, which is why it doesn't break it up.
There are 3 other things you can do, off the top of my head.
You can disable the host parsing in the database. See postgres documentation for details. E.g. something like ALTER TEXT SEARCH CONFIGURATION your_parser_config
DROP MAPPING FOR url, url_path
You can write your own custom dictionary.
You can pre-parse your data before it's inserted into the database in some manner (maybe splitting all domains before going into the database).
I had a similar issue to you last year and opted for solution (2), above.
My solution was to write a custom dictionary that splits words up on non-word characters. A custom dictionary is a lot easier & quicker to write than a new parser. You still have to write C tho :)
The dictionary I wrote would return something like 'www.facebook.com':4, 'com':3, 'facebook':2, 'www':1' for the 'www.facebook.com' domain (we had a unique-ish scenario, hence the 4 results instead of 3).
The trouble with a custom dictionary is that you will no longer get stemming (ie: www.books.com will come out as www, books and com). I believe there is some work (which may have been completed) to allow chaining of dictionaries which would solve this problem.
First off in case you're not aware, tsearch2 is deprecated in favor of the built-in functionality:
http://www.postgresql.org/docs/9/static/textsearch.html
As for your actual question, google.com gets recognized as a host by the parser:
http://www.postgresql.org/docs/9.0/static/textsearch-parsers.html
If you don't want this to occur, you'll need to pre-process your text accordingly (or use a custom parser).