プロジェクト

全般

プロフィール

Vote #73733

完了

Accept dots in JSONP callback

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
110
issue_org_id:
13718
author_id:
76139
assigned_to_id:
1
comments:
11
status_id:
5
tracker_id:
2
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

When i try use mootools Request.JSONP Request it's not working.
For example http://avtehnik.m.redmine.org/projects.json?callback=my.Handler&key=0e96523a813ecf559ddba696a4f9549489aa8781 , the callback is my.Handler but in response dot is not appear myHandler({"projects":....


journals

According to "json-p.org":http://www.json-p.org ??The proposed solution??, allowed syntax could include these forms:
<pre>
functionName({JSON});

obj.functionName({JSON});

obj["function-name"]({JSON});
</pre>

For now, only the first one is partly supported whith ??functionName?? bein composed of digits and characters A to Z plus _ (see source:/trunk/lib/redmine/views/builders/json.rb@11272#L30).

Theoretically ??functionName?? should also be checked as being a "valid javascript identifier name":http://mathiasbynens.be/notes/javascript-identifiers, thus allowing some Unicode characters, but this might look a bit overkill?

--------------------------------------------------------------------------------
I would definitely agree that at least @foo.bar(...)@ support should be added (which I assume is what this issue originally asked for specifically, based on the subject history).

Some JS libraries e.g. Dojo use a global namespace for their JSONP request support so that only one global variable is created instead of multiple, and currently the regex in http://www.redmine.org/projects/redmine/repository/entry/trunk/lib/redmine/views/builders/json.rb will strip periods, making Redmine's JSONP REST API unusable with these JS libraries.

Here's an example of the kind of function names Dojo's @dojo/request/script@ module uses: @dojo_request_script_callbacks.dojo_request_script0@
--------------------------------------------------------------------------------
Angular JS also uses object based JSONP callbacks.

Please support this ! :)

https://github.com/angular/angular.js/issues/1551
--------------------------------------------------------------------------------
I added the dot to the regex, which at least fixes the obj.functionName({JSON}); example.

https://github.com/blowsie/redmine/commit/6d476160cdbc4eee17ae481f873fc07dc8cdf571
--------------------------------------------------------------------------------
I just spent several hours implementing workarounds because Redmine does not adhere to the JSONP specification. I'm still not done... I'm using Angular JS like the user in comment #3. This issue is years old and has a link to a commit (comment #4) that contains a 1 line fix.

What needs to happen for this to be included in the next Redmine release.
--------------------------------------------------------------------------------
Sam Blowes wrote:
> I added the dot to the regex, which at least fixes the obj.functionName({JSON}); example.
>
> https://github.com/blowsie/redmine/commit/6d476160cdbc4eee17ae481f873fc07dc8cdf571

lib/redmine/views/builders/json.rb for trunk r13339:
<pre><code class="diff">
@@ -27,7 +27,7 @@ def initialize(request, response)
super
callback = request.params[:callback] || request.params[:jsonp]
if callback && Setting.jsonp_enabled?
- self.jsonp = callback.to_s.gsub(/[^a-zA-Z0-9_]/, '')
+ self.jsonp = callback.to_s.gsub(/[^a-zA-Z0-9_.]/, '')
end
end
</code></pre>

--------------------------------------------------------------------------------
Could we pretty please have this single character added to this line?

Just for your sanity here is a description of the regex;
<pre>
// [^a-zA-Z0-9_.]
//
// Options: Case sensitive; ^$ match at line breaks; dot doesn’t match line breaks; Regex syntax only
//
// Match any single character that is NOT present in the list below and that is NOT a line break character (line feed) «[^a-zA-Z0-9_.]»
// A character in the range between “a” and “z” (case sensitive) «a-z»
// A character in the range between “A” and “Z” (case sensitive) «A-Z»
// A character in the range between “0” and “9” «0-9»
// A single character from the list “_.” «_.»
</pre>
--------------------------------------------------------------------------------
Perhaps someone with SVN skills would kindly submit my patch to the Redmine SVN repo.
https://github.com/redmine/redmine/pull/68

Regards.
--------------------------------------------------------------------------------
https://bitbucket.org/redmine/redmine/pull-requests/3/improve-jsonp-support/diff
--------------------------------------------------------------------------------
Sam Blowes wrote:
> https://bitbucket.org/redmine/redmine/pull-requests/3/improve-jsonp-support/diff

One of reasons which pull request is bad is if source repository is deleted, diff is also deleted.
--------------------------------------------------------------------------------
Fix committed, thanks.
--------------------------------------------------------------------------------


related_issues

relates,Closed,11469,JSONP support

Admin Redmine さんが約4年前に更新

  • カテゴリREST API_32 にセット
  • 対象バージョン3.3.0_110 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0