nextcloud / nextcloud/maps

Favourites API incorrectly processes extensions

Open
#216 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature: :star: favorites
Dominant language
JavaScript
Stars
598
Forks
113
PR merge metrics
No merged PRs in 30d

Description

extensions in a gpx file are a set of XML attributes of the form

Favorite Personal #eeee10

These get rendered into JSON as a JSONObject:

{"name":"Favorite","lat":47.654394331045,"lng":-122.17156600952,"category":"Personal","comment":"","extensions":{"color":"#eeee10"}}

Which means that $extensions in the FavoritesApiController.php is an array. However, the FavoritesService.php tries to put $extensions directly into the database meaning that 'Array' gets deposited as the string.

I've fixed this by adding json_encode/json_decode as in the below patch so my OsmAnd plugin development can limp along, but this won't account correctly for import/export so it really needs fixing properly.

diff --git a/lib/Service/FavoritesService.php b/lib/Service/FavoritesService.php
index 00fd2d6..e0dab06 100644
--- a/lib/Service/FavoritesService.php
+++ b/lib/Service/FavoritesService.php
@@ -75,7 +75,7 @@ class FavoritesService {
$lng = floatval($row['lng']);
$category = $row['category'];
$comment = $row['comment'];

  •        $extensions = $row['extensions'];
    
  •        $extensions = json_decode($row['extensions']);
           array_push($favorites, [
               'id' => $id,
               'name' => $name,
    

@@ -117,7 +117,7 @@ class FavoritesService {
$lng = floatval($row['lng']);
$category = $row['category'];
$comment = $row['comment'];

  •        $extensions = $row['extensions'];
    
  •        $extensions = json_decode($row['extensions']);
           $favorite = [
               'id' => $id,
               'name' => $name,
    

@@ -149,7 +149,7 @@ class FavoritesService {
'lng' => $qb->createNamedParameter($lng, IQueryBuilder::PARAM_STR),
'category' => $qb->createNamedParameter($category, IQueryBuilder::PARAM_STR),
'comment' => $qb->createNamedParameter($comment, IQueryBuilder::PARAM_STR),

  •            'extensions' => $qb->createNamedParameter($extensions, IQueryBuilder::PARAM_STR)
    
  •            'extensions' => $qb->createNamedParameter(json_encode($extensions), IQueryBuilder::PARAM_STR)
           ]);
       $req = $qb->execute();
       $favoriteId = $qb->getLastInsertId();
    

@@ -229,7 +229,7 @@ class FavoritesService {
$qb->set('comment', $qb->createNamedParameter($comment, IQueryBuilder::PARAM_STR));
}
if ($extensions !== null) {

  •        $qb->set('extensions', $qb->createNamedParameter($extensions, IQueryBuilder::PARAM_STR));
    
  •        $qb->set('extensions', $qb->createNamedParameter(json_encode($extensions), IQueryBuilder::PARAM_STR));
       }
       $qb->where(
           $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
    

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read lib/Service/FavoritesService.php and FavoritesApiController.php, then trace how extensions move through the favourites import and export paths. Verify how the database stores and retrieves the value; done means extension data remains structured rather than becoming the string "Array" across API and import/export flows.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.