<commit_before>const urlUtil = require('url');
const React = require('react');
const {isArray} = require('lodash');

const assign = require('object-assign');

const Legend = React.createClass({
    propTypes: {
        layer: React.PropTypes.object,
        legendHeigth: React.PropTypes.number,
        legendWidth: React.PropTypes.number,
        legendOptions: React.PropTypes.string
    },
    getDefaultProps() {
        return {
            legendHeigth: 12,
            legendWidth: 12,
            legendOptions: "forceLabels:on;fontSize:10"
        };
    },
   render() {
       if (this.props.layer && this.props.layer.type === "wms" && this.props.layer.url) {
           let layer = this.props.layer;
           const url = isArray(layer.url) ?
               layer.url[Math.floor(Math.random() * layer.url.length)] :
               layer.url.replace(/[?].*$/g, '');

           let urlObj = urlUtil.parse(url);
           let query = assign({}, {
               service: "WMS",
               request: "GetLegendGraphic",
               format: "image/png",
               height: this.props.legendHeigth,
               width: this.props.legendWidth,
               layer: layer.name,
               style: layer.style || null,
               version: layer.version || "1.3.0",
               LEGEND_OPTIONS: this.props.legendOptions
               // SCALE TODO
           }, layer.legendParams || {});

           let legendUrl = urlUtil.format({
               host: urlObj.host,
               protocol: urlObj.protocol,
               pathname: urlObj.pathname,
               query: query
           });
           return <img src={legendUrl} style={{maxWidth: "100%"}}/>;
       }
       return null;
   }
});
module.exports = Legend;<commit_msg>Fixes #889: apply SLD_BODY in GetLegendGraphic if defined for layer (#890)<commit_after>const urlUtil = require('url');
const React = require('react');
const {isArray} = require('lodash');

const assign = require('object-assign');

const Legend = React.createClass({
    propTypes: {
        layer: React.PropTypes.object,
        legendHeigth: React.PropTypes.number,
        legendWidth: React.PropTypes.number,
        legendOptions: React.PropTypes.string
    },
    getDefaultProps() {
        return {
            legendHeigth: 12,
            legendWidth: 12,
            legendOptions: "forceLabels:on;fontSize:10"
        };
    },
   render() {
       if (this.props.layer && this.props.layer.type === "wms" && this.props.layer.url) {
           let layer = this.props.layer;
           const url = isArray(layer.url) ?
               layer.url[Math.floor(Math.random() * layer.url.length)] :
               layer.url.replace(/[?].*$/g, '');

           let urlObj = urlUtil.parse(url);
           let query = assign({}, {
               service: "WMS",
               request: "GetLegendGraphic",
               format: "image/png",
               height: this.props.legendHeigth,
               width: this.props.legendWidth,
               layer: layer.name,
               style: layer.style || null,
               version: layer.version || "1.3.0",
               LEGEND_OPTIONS: this.props.legendOptions
               // SCALE TODO
           }, layer.legendParams || {},
           layer.params && layer.params.SLD_BODY ? {SLD_BODY: layer.params.SLD_BODY} : {});

           let legendUrl = urlUtil.format({
               host: urlObj.host,
               protocol: urlObj.protocol,
               pathname: urlObj.pathname,
               query: query
           });
           return <img src={legendUrl} style={{maxWidth: "100%"}}/>;
       }
       return null;
   }
});
module.exports = Legend;
{'fraction_non_alphanumeric': 0.13402061855670103, 'fraction_numerical': 0.008138903960933261, 'mean_word_length': 1.7868480725623583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4550879', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1039, 'n_words': 205}