[DRE-commits] [ruby-actionpack-xml-parser] 01/03: Imported Upstream version 1.0.2

Klee Dienes klee at moszumanska.debian.org
Mon Aug 31 16:44:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

klee pushed a commit to branch master
in repository ruby-actionpack-xml-parser.

commit 7ed73736544b4caf70ee0b30ac6c3442f153c1e9
Author: Klee Dienes <klee.dienes at hadronindustries.com>
Date:   Mon Aug 31 07:31:09 2015 -0400

    Imported Upstream version 1.0.2
---
 LICENSE                                  | 22 +++++++++
 README.md                                | 27 ++++++++++
 lib/action_dispatch/xml_params_parser.rb | 54 ++++++++++++++++++++
 lib/actionpack/xml_parser.rb             |  1 +
 metadata.yml                             | 84 ++++++++++++++++++++++++++++++++
 5 files changed, 188 insertions(+)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f52a141
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Prem Sichanugrist
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..57e45e2
--- /dev/null
+++ b/README.md
@@ -0,0 +1,27 @@
+actionpack-xml\_parser
+======================
+
+A XML parameters parser for Action Pack (removed from core in Rails 4.0)
+
+Installation
+------------
+
+Include this gem into your Gemfile:
+
+```ruby
+gem 'actionpack-xml_parser'
+```
+
+Then, add `ActionDispatch::XmlParamsParser` middleware after `ActionDispatch::ParamsParser`
+in `config/application.rb`:
+
+```ruby
+config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::XmlParamsParser
+```
+
+You may need to require the `ActionDispatch::XmlParamsParser` manually. Add the following 
+in your `config/application.rb`:
+
+```ruby
+require 'action_dispatch/xml_params_parser'
+```
diff --git a/lib/action_dispatch/xml_params_parser.rb b/lib/action_dispatch/xml_params_parser.rb
new file mode 100644
index 0000000..b5f785d
--- /dev/null
+++ b/lib/action_dispatch/xml_params_parser.rb
@@ -0,0 +1,54 @@
+require 'active_support/core_ext/hash/conversions'
+require 'action_dispatch/http/request'
+require 'active_support/core_ext/hash/indifferent_access'
+
+module ActionDispatch
+  class XmlParamsParser
+    def initialize(app)
+      @app = app
+    end
+
+    def call(env)
+      if params = parse_formatted_parameters(env)
+        env["action_dispatch.request.request_parameters"] = params
+      end
+
+      @app.call(env)
+    end
+
+    private
+      def parse_formatted_parameters(env)
+        request = Request.new(env)
+
+        return false if request.content_length.zero?
+
+        mime_type = content_type_from_legacy_post_data_format_header(env) ||
+          request.content_mime_type
+
+        if mime_type == Mime::XML
+          # Rails 4.1 moved #deep_munge out of the request and into ActionDispatch::Request::Utils
+          munger = defined?(Request::Utils) ? Request::Utils : request
+
+          data = munger.deep_munge(Hash.from_xml(request.body.read) || {})
+          request.body.rewind if request.body.respond_to?(:rewind)
+          data.with_indifferent_access
+        else
+          false
+        end
+      rescue Exception => e # XML code block errors
+        logger(env).debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
+
+        raise ActionDispatch::ParamsParser::ParseError.new(e.message, e)
+      end
+
+      def content_type_from_legacy_post_data_format_header(env)
+        if env['HTTP_X_POST_DATA_FORMAT'].to_s.downcase == 'xml'
+          Mime::XML
+        end
+      end
+
+      def logger(env)
+        env['action_dispatch.logger'] || ActiveSupport::Logger.new($stderr)
+      end
+  end
+end
diff --git a/lib/actionpack/xml_parser.rb b/lib/actionpack/xml_parser.rb
new file mode 100644
index 0000000..95ca8ba
--- /dev/null
+++ b/lib/actionpack/xml_parser.rb
@@ -0,0 +1 @@
+require 'action_dispatch/xml_params_parser'
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..f37be8f
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,84 @@
+--- !ruby/object:Gem::Specification
+name: actionpack-xml_parser
+version: !ruby/object:Gem::Version
+  version: 1.0.2
+platform: ruby
+authors:
+- Prem Sichanugrist
+autorequire: 
+bindir: bin
+cert_chain: []
+date: 2015-04-17 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+  name: actionpack
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: 4.0.0
+    - - "<"
+      - !ruby/object:Gem::Version
+        version: '5'
+  type: :runtime
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: 4.0.0
+    - - "<"
+      - !ruby/object:Gem::Version
+        version: '5'
+- !ruby/object:Gem::Dependency
+  name: rake
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: '0'
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: '0'
+description: 
+email: s at sikac.hu
+executables: []
+extensions: []
+extra_rdoc_files:
+- README.md
+files:
+- LICENSE
+- README.md
+- lib/action_dispatch/xml_params_parser.rb
+- lib/actionpack/xml_parser.rb
+homepage: http://www.rubyonrails.org
+licenses:
+- MIT
+metadata: {}
+post_install_message: 
+rdoc_options:
+- "--main"
+- README.md
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+  requirements:
+  - - ">="
+    - !ruby/object:Gem::Version
+      version: 1.9.3
+required_rubygems_version: !ruby/object:Gem::Requirement
+  requirements:
+  - - ">="
+    - !ruby/object:Gem::Version
+      version: '0'
+requirements: []
+rubyforge_project: 
+rubygems_version: 2.4.6
+signing_key: 
+specification_version: 4
+summary: XML parameters parser for Action Pack (removed from core in Rails 4.0)
+test_files: []

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-actionpack-xml-parser.git



More information about the Pkg-ruby-extras-commits mailing list