HelloZeroNet / HelloZeroNet/ZeroNet

fileQuery: does the implementation match the documentation?

Ouverte
#1,689 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
18.8k
Forks
2.3k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

[The documentation](https://github.com/HelloZeroNet/Documentation/blob/master/docs/site_development/zeroframe_api_reference.md) states:

> ### fileQuery _dir_inner_path, query_
> Simple json file query command
>
> Parameter | Description
> --- | ---
> **dir_inner_path** | Pattern of queried files
> **query** | Query command (optional)
>
> **Return**: Matched content
>
> **Query examples:**
>
> - `["data/users/*/data.json", "topics"]`: Returns all topics node from all user files
> - `["data/users/*/data.json", "comments.1@2"]`: Returns `user_data["comments"]["1@2"]` value from all user files
> - `["data/users/*/data.json", ""]`: Returns all data from users files
> - `["data/users/*/data.json"]`: Returns all data from users files (same as above)
>
> **Example:**
> ```coffeescript
> @cmd "fileQuery", ["data/users/*/data.json", "topics"], (topics) =>
> topics.sort (a, b) -> # Sort by date
> return a.added - b.added
> for topic in topics
> @log topic.topic_id, topic.inner_path, topic.title
> ```

Since there is no definition there, what the "pattern of queried files" is, it is logical to assume that the pattern works similar to the usual wildcard file pattern. So, if one queries "folder/data.json", she should get back exactly 1 result. In fact it is not so:

```
Page.cmd("fileQuery", "data/users/content.json", function(r) {console.log(r.length);})
7
```
The result contains files from the whole `data/users/` subtree.

If the pattern has no `/*/` part, the implementation silently assumes it before the last part of the file path:

```
if "/*/" in path_pattern: # Wildcard search
root_dir, file_pattern = path_pattern.replace("\\", "/").split("/*/")
else: # No wildcard
root_dir, file_pattern = re.match("(.*)/(.*?)$", path_pattern.replace("\\", "/")).groups()
```

Is it actually how it is supposed to work? What is wrong: the documentation or the implementation?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Read docs/site_development/zeroframe_api_reference.md and compare its fileQuery examples with the implementation logic shown in the issue. Reproduce the Page.cmd("fileQuery", "data/users/content.json", ...) case, then determine whether the documented pattern or the implementation defines the intended behavior. Done means the documentation and behavior agree, with the discrepancy resolved and covered by an appropriate test.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, python
Domaine
api, documentation
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.